From patchwork Wed Apr 27 20:13:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1623217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=mUPlwLxB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpVLf08Tpz9s5V for ; Thu, 28 Apr 2022 06:13:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 297F23857C50 for ; Wed, 27 Apr 2022 20:13:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 297F23857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651090405; bh=KWF0hSUs7d6mIxYfNTKbzC8PUMTadRVjWaTo0xca+Jg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mUPlwLxB3aOQIQYANFJ+WLy9LloMdR4CEyxM/+WljO/oYczgNv5tIe3UXSqEvEw8x Co39DyIqb1Erg6o4yWEXa/5+yEyjm/MZ52J6N2f3swfyBAgOUJcTNoxWYEWlOhg93V rycr2HUkf7tXI9cYRWbhRDWpNO2loJ1n6EHXzlUY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 7FA35385842B for ; Wed, 27 Apr 2022 20:13:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7FA35385842B Received: by mail-pl1-x629.google.com with SMTP id u7so2504085plg.13 for ; Wed, 27 Apr 2022 13:13:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KWF0hSUs7d6mIxYfNTKbzC8PUMTadRVjWaTo0xca+Jg=; b=VCMQBQCyre0CQbrSud8MTpE8ct2ToLY5IAx/zLmh7eDlaRXypFfELCdrIRseP9TG3i eoqUjeLSjd8DEPctWwljcA0ZNujh5Gij2OwRZtLa0bBtwq+ogFL5SnJyVlmomwarCdW9 kCKzG2Wx1F98FkMiE/ExKzLnyaqdQvcGTxn6HMarwfpta9cmXGx4XHrEMkthYW/0pVFF qQGs1QpfI8h6Ez7dAO80x01tSFylNgKGQb4VR+3SGFToHU+7J3hdtRD+SxkChXvRGAnu m7mEL9pnoIGEBjfyFDidpcgMgm+B6kp8RYDH+YWDYwZg2v0UlEM6qjOWro6Ega/bdYVv pEpg== X-Gm-Message-State: AOAM530n3uyFKaeJR/Nz0Q6n0duYAD3LR/fGfPeH+b3N6dy+DtQLWkoj sCfjLEeAkrTIYbEa5nPgRlEoy2Lnzw0= X-Google-Smtp-Source: ABdhPJyh9ZbdTzke1ZEP2uK5mTw4X3LW9nfvzlIr8eBEC8yeL8yOMA/iE2yrZH03o7dejgDfKPDiQQ== X-Received: by 2002:a17:90a:4bc2:b0:1b8:cdd3:53e2 with SMTP id u2-20020a17090a4bc200b001b8cdd353e2mr44790359pjl.219.1651090389232; Wed, 27 Apr 2022 13:13:09 -0700 (PDT) Received: from localhost.localdomain ([64.145.94.63]) by smtp.googlemail.com with ESMTPSA id l22-20020a656816000000b003c14af505fesm140342pgt.22.2022.04.27.13.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 13:13:08 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2] sysdeps: Add 'get_fast_jitter' interace in fast-jitter.h Date: Wed, 27 Apr 2022 15:13:02 -0500 Message-Id: <20220427201302.2525203-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220404213942.652799-1-goldstein.w.n@gmail.com> References: <20220404213942.652799-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 'get_fast_jitter' is meant to be used purely for performance purposes. In all cases it's used it should be acceptable to get no randomness (see default case). An example use case is in setting jitter for retries between threads at a lock. There is a performance benefit to having jitter, but only if the jitter can be generated very quickly and ultimately there is no serious issue if no jitter is generated. The implementation generally uses 'HP_TIMING_NOW' iff it is inlined (avoid any potential syscall paths). Reviewed-by: H.J. Lu --- sysdeps/generic/fast-jitter.h | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sysdeps/generic/fast-jitter.h diff --git a/sysdeps/generic/fast-jitter.h b/sysdeps/generic/fast-jitter.h new file mode 100644 index 0000000000..4dd53e3475 --- /dev/null +++ b/sysdeps/generic/fast-jitter.h @@ -0,0 +1,42 @@ +/* Fallback for fast jitter just return 0. + Copyright (C) 2019-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _FAST_JITTER_H +# define _FAST_JITTER_H + +# include +# include + +/* Baseline just return 0. We could create jitter using a clock or + 'random_bits' but that may imply a syscall and the goal of + 'get_fast_jitter' is minimal overhead "randomness" when such + randomness helps performance. Adding high overhead the function + defeats the purpose. */ +static inline uint32_t +get_fast_jitter (void) +{ +# if HP_TIMING_INLINE + hp_timing_t jitter; + HP_TIMING_NOW (jitter); + return (uint32_t) jitter; +# else + return 0; +# endif +} + +#endif