From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 1439B385735B for ; Wed, 15 Jun 2022 17:41:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1439B385735B Received: by mail-pj1-x1034.google.com with SMTP id t3-20020a17090a510300b001ea87ef9a3dso2696653pjh.4 for ; Wed, 15 Jun 2022 10:41:36 -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=n3TR9NAemrX9ZBmOvWNJAX1iA0y/rd7EOTZktjMvnz0=; b=NWwxjpmR4NhZ6Wzo30ilLEsjzf7bEyGksfeom01kUjR5sFgC3JLxdPeyDKafPwF1BR YSuvyCdLpiY8nLU6dhXzeGurT6qSh8ctt0l60H7KRiYpdMisZoffYlTWtr78wqXwTjrb dJ6mlH9JSFS36f7JxOEaQCQOJBlS+iaH2PflfXYon9JPf3flpLEOfvXF6l4y2BGyVxm2 +2ktL1oqXW22wSImr3keBBKljLrtAuJyJk24lFsugF8f15e3hB9WXQH/3bLQdRQovdjm cgeYEQPDYftSTL+1LD4LFABsyNLNeyii/o65M72GApw3/QGzjmyYc9Ri5mu7RNoZ1pX9 hJ/A== X-Gm-Message-State: AJIora/nbEStS83ZyBXVAsEg8X48s7NsH6fvdbnEoqAI0T2eaP+X81WA S2A9QNkPqDnumv32hfr+yYGB9SJFtwo= X-Google-Smtp-Source: AGRyM1vlRiOLpFk/HtU1j7lmRbHtrvD980YutX+WfUOn8QV9CoqqXyIvnkTjHo6k0p/0YO+jxk1PSA== X-Received: by 2002:a17:902:eb90:b0:163:e4c1:b2fc with SMTP id q16-20020a170902eb9000b00163e4c1b2fcmr700419plg.159.1655314895091; Wed, 15 Jun 2022 10:41:35 -0700 (PDT) Received: from noah-tgl.. ([2600:1010:b02a:171c:1ecd:bd08:26b4:64f9]) by smtp.gmail.com with ESMTPSA id y23-20020a17090264d700b001640594376dsm9595688pli.183.2022.06.15.10.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 10:41:34 -0700 (PDT) From: Noah Goldstein To: libc-alpha@sourceware.org Subject: [PATCH v4 2/2] x86: Add bounds `x86_non_temporal_threshold` Date: Wed, 15 Jun 2022 10:41:29 -0700 Message-Id: <20220615174129.620476-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220615174129.620476-1-goldstein.w.n@gmail.com> References: <20220615002533.1741934-2-goldstein.w.n@gmail.com> <20220615174129.620476-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-List-Received-Date: Wed, 15 Jun 2022 17:41:37 -0000 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 | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/manual/tunables.texi b/manual/tunables.texi index 1482412078..49daf3eb4a 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: 0x0, 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..f94ff2df43 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -931,8 +931,12 @@ 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. Not the '>> 4' also reflect the bound + in the manual. */ TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold, - 0, SIZE_MAX); + 0, 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, -- 2.34.1