From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 627E93858D37; Tue, 20 Sep 2022 03:38:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 627E93858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663645115; bh=cJcgR5ac+SD90MQb8RdLd4dgtsdZ4v4GPFgsqyHvqn8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NvSMsLScsnFAraj9F9u0D/LvAQMeoNaDBdhZuy9Z9jSkZ3vgm2gUooFBw+pPKoh2Y jora1RQmHcmayqO+ZtafZWIcVNuobJVAcRt38FWGcJvZaTKZzpc5p/V9QFefQJ0Z0Y 2oesf51Sy/c62zO775Dn2xa81+92+a9mm6vFU6rE= From: "rodgertq at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/106772] atomic::wait shouldn't touch waiter pool if used platform wait Date: Tue, 20 Sep 2022 03:38:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rodgertq at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: 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://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106772 --- Comment #3 from Thomas Rodgers --- Since this latter point has come up before, I want to additionally note that the optimization to use an atomic count of waiters per-waiter pool bucket m= eans that a call to notify_one/notify_all is roughly 25x faster based on my test= ing than naively issuing a syscall to FUTEX_WAKE when there is no possibility of the wake being issued to a waiter. 2022-09-19T20:34:28-07:00 Running ./benchmark Run on (20 X 4800 MHz CPU s) CPU Caches: L1 Data 48 KiB (x10) L1 Instruction 32 KiB (x10) L2 Unified 1280 KiB (x10) L3 Unified 24576 KiB (x1) Load Average: 0.69, 0.61, 1.30 ***WARNING*** CPU scaling is enabled, the benchmark real time measurements = may be noisy and will incur extra overhead. ------------------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------------------ BM_empty_notify_checked 3.79 ns 3.79 ns 179929051 BM_empty_notify_syscall 94.1 ns 93.9 ns 7477997 For types that can use a FUTEX directly (e.g. int) there is no place to put that extra atomic to perform this check, so we can either have the type tha= t is directly usable by the underlying platform be significantly more expensive = to call, or we can use the waiter count in the waiter_pool.=