From patchwork Wed Jun 15 18:32:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 55110 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 202C93857424 for ; Wed, 15 Jun 2022 18:33:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 202C93857424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655317986; bh=rNyw6QiLLMzTeVq0MGVmYDNWQ+bmdnZ+nr2qbvJ3EEI=; 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=i9h13V8Z9HWtGcaslH79gBxBGlFuYyvmDgZvxlVepHZ4yY6D/DfTNZN90XaiCMMcJ lqVZb6uAZNtzi0qYgjju02g5TdaAmM0SEWYAeMauRm08L5RiVOe7kZVmRO4itsFi4e epHVdtKkZ3JNCSicH7KHALv20/h3A/KCVUA6S9nM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 7812C3858D32 for ; Wed, 15 Jun 2022 18:32:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7812C3858D32 Received: by mail-pl1-x631.google.com with SMTP id d5so8518079plo.12 for ; Wed, 15 Jun 2022 11:32:44 -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=rNyw6QiLLMzTeVq0MGVmYDNWQ+bmdnZ+nr2qbvJ3EEI=; b=Hm8Am5m6RCHpQoL7hxcf/pX9PBQqMgmWT2T4DlMVpF1WKCNpTHH3Bfcm5sDDsWL2Nr 2PCV05WqWH1rhzx30TumdUx36loKjvuKpx6JGjNJlwzz2rAc1qQvhumXMWZS4qiL/Tmc WOwVNxSqXtzAybEpv7G9Ite2rke6c8P1Mo0qk/UllGX+d6zx4aPw6UCPZd7GgdrCfmZ6 dfmPBLKEH/+N4dZ7cBiJJXRQXx4jYlaAoimn9aS2ns+7YWQ+abSwDaMkaq8RjVr4Gexd WQjh3GGMW0YROpHvebw5jmvpip3buBpVRqrPhAN90qBnszYdtL5atSzYGGdedY7PbwyS EwFQ== X-Gm-Message-State: AJIora+r2YKT/OeCJPRE/FiOlC/RbGlMPia+Flc1SUv3Kt+bkXN24eE1 XgxXc5VFTERI+lQA1Dlr2jGHTk1C2ys= X-Google-Smtp-Source: AGRyM1uhO1FvzEyf1FIZUySZbGesmNaX7WGCbsKCk24FXGF4P3jt0g7ae1uIWdsFoGitTxQ9lUA1Eg== X-Received: by 2002:a17:902:ce92:b0:167:585b:af40 with SMTP id f18-20020a170902ce9200b00167585baf40mr846499plg.153.1655317963278; Wed, 15 Jun 2022 11:32:43 -0700 (PDT) Received: from noah-tgl.. ([192.55.60.47]) by smtp.gmail.com with ESMTPSA id p7-20020a17090a428700b001e2f383110bsm2182149pjg.11.2022.06.15.11.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 11:32:43 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 2/2] x86: Add bounds `x86_non_temporal_threshold` Date: Wed, 15 Jun 2022 11:32:40 -0700 Message-Id: <20220615183240.623735-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220615174129.620476-2-goldstein.w.n@gmail.com> References: <20220615174129.620476-2-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The lower-bound (131072) and upper-bound (SIZE_MAX / 16) are assumed by memmove-vec-unaligned-erms. The lower-bound is needed because memmove-vec-unaligned-erms unrolls the loop aggressively in the L(large_memset_4x) case. The upper-bound is needed because memmove-vec-unaligned-erms right-shifts the value of `x86_non_temporal_threshold` by LOG_4X_MEMCPY_THRESH (4) which without a bound may overflow. The lack of lower-bound can be a correctness issue. The lack of upper-bound cannot. --- manual/tunables.texi | 2 +- sysdeps/x86/dl-cacheinfo.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/manual/tunables.texi b/manual/tunables.texi index 1482412078..a420ed6206 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -47,7 +47,7 @@ glibc.malloc.mxfast: 0x0 (min: 0x0, max: 0xffffffffffffffff) glibc.elision.skip_lock_busy: 3 (min: -2147483648, max: 2147483647) glibc.malloc.top_pad: 0x0 (min: 0x0, max: 0xffffffffffffffff) glibc.cpu.x86_rep_stosb_threshold: 0x800 (min: 0x1, max: 0xffffffffffffffff) -glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x0, max: 0xffffffffffffffff) +glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x20000, max: 0x0fffffffffffffff) glibc.cpu.x86_shstk: glibc.cpu.hwcap_mask: 0x6 (min: 0x0, max: 0xffffffffffffffff) glibc.malloc.mmap_max: 0 (min: -2147483648, max: 2147483647) diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h index cc3b840f9c..b4ff385ae1 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -931,8 +931,13 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX); TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX); + /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of + 'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best + if that operation cannot overflow. 0x20000 (131072) because the + L(large_memset_4x) case aggressively unrolls the loop. Both values are + reflected in the manual. */ TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold, - 0, SIZE_MAX); + 0x20000, SIZE_MAX >> 4); TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshold, minimum_rep_movsb_threshold, SIZE_MAX); TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshold, 1,