From patchwork Wed Jun 15 19:52:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1643963 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=Spu1QPWx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LNbZM1lfFz9sG2 for ; Thu, 16 Jun 2022 05:52:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF93F3857B98 for ; Wed, 15 Jun 2022 19:52:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF93F3857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655322775; bh=sJIdbo1tEkfz8Fcqah9CuFy+6bcYoB+3p6koYhrNDJo=; 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=Spu1QPWx+uAqNoKSS/F1iutz0nYLYgztI14HCFgvdq5lbiJQhmmfjzlQHkfGDbeGP ul6OyacNybtOkuq4cjeV4St/dlYmXMRklad1lVV71N7BovstmCa2b6OiMDzbUv2daS yW2UrZMzTLfeNIou3gNzWLv+tRdm2qew4jU4/RMA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id E67813858D32 for ; Wed, 15 Jun 2022 19:52:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E67813858D32 Received: by mail-pg1-x52d.google.com with SMTP id r5so5601337pgr.3 for ; Wed, 15 Jun 2022 12:52:40 -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=sJIdbo1tEkfz8Fcqah9CuFy+6bcYoB+3p6koYhrNDJo=; b=ISRxTYzxC853KtODsGqfNcAxdDlMwu2KgSzoJdUJa/8jUSgNMlV0LlGXBqkEBTNalM 8MYZTajhG9BxbFummiPPyUig2z2TA313Nofk8gpqT7Ki54gP2mx1hmNli4YF/9bUNUZX 7vr4cJ+voGkVLRk44hlwFAwVQF/RNp+Zn7BRJg/3qx2ztIu8pQuk4Zz1/WcEErcflmVW y/1tqxRHxZpE9bsuDfMxlsR8FSMfALBWeEETDt8ucdhIobrRmwAwGZGm6c42CYY4iCSo VeJ/IG1sF6HyJsch8VyM/n3YAjDuSFQQ2zHDpe1Pd25MhCmYJ9w12z7xdxzeTjptYl8Q P6JA== X-Gm-Message-State: AJIora/TmtvhSoGhQ2STRAjK+Key+WKLFYCqiJR61EjRob7LZ1+X5V3o uvXVuOo1MCTN9l/xxlah9dEVy4SJo7o= X-Google-Smtp-Source: AGRyM1saY9GCZTRckV8VqC5O2DqSNqx1w/v/2pL9H4QasxSMpAZNGuyTHpjGRUuJgjwMpxBMqfxZjg== X-Received: by 2002:a63:8043:0:b0:3fc:d9e7:2357 with SMTP id j64-20020a638043000000b003fcd9e72357mr1194063pgd.405.1655322759721; Wed, 15 Jun 2022 12:52:39 -0700 (PDT) Received: from noah-tgl.. ([192.55.60.47]) by smtp.gmail.com with ESMTPSA id i3-20020a17090ac40300b001e29ddf9f4fsm26288pjt.3.2022.06.15.12.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 12:52:39 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v6 2/3] x86: Add bounds `x86_non_temporal_threshold` Date: Wed, 15 Jun 2022 12:52:37 -0700 Message-Id: <20220615195237.3685347-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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The lower-bound (16448) 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 | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/manual/tunables.texi b/manual/tunables.texi index 1482412078..2c076019ae 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: 0x4040, 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..c493956259 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -931,8 +931,14 @@ 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. Minimum of 0x4040 (16448) because the + L(large_memset_4x) loops need 64-byte to cache align and enough space for + at least 1 iteration of 4x PAGE_SIZE unrolled 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,