From patchwork Wed Aug 14 06:37:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1972205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=SW5eT0YA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WkJV46wQ6z1yZl for ; Wed, 14 Aug 2024 16:38:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BDDA5385840F for ; Wed, 14 Aug 2024 06:38:02 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id E88753858C5F for ; Wed, 14 Aug 2024 06:37:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E88753858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E88753858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723617468; cv=none; b=sZgzt/NayihjlKcdVTJSLRkybI0Zj3CkCWxYjOp2F1/CtuXLX38rONLQiXBgq6RoyggiKmA6XA1uwTFj2EVRqGzuWdP5qmrJ4FwV/4QdjPWpcTFn23NpDhW/lZ0WH2t5M7w9gzAN65RyBYyEypKFQj2g8DJxKtAalj7xCCXswJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723617468; c=relaxed/simple; bh=fmWVJGuLlOtXrrl+5SgJ4BspRT6/0ZjfuPIHrUhFu0Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=v51H/1+nzITAylXeN5rT3/H+0pvnNF4qCUaZ///jpkeWD0b6Udz9IPjSnJzxy7pxI/5Ginu8jHnFXcyr4iorr44izyfdlIXzdFnfoLQdu7yFAh87wMWmLXPq2lMwEGCpuDoK6zPnma+yQvZivVGPd+kIGzHGmj4YO7PDzzHiE7w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5bb8e62570fso7518242a12.1 for ; Tue, 13 Aug 2024 23:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723617465; x=1724222265; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S50gDP85bfIUkvmV9LMgIBOxA9ssCMFmf5fjm28/XhI=; b=SW5eT0YATK2e7x0snZg5cwcMNZDXqc2hppYKBHTXoWQArqk6BzVWwjGUIpSIBakzh1 hiiFssmeU1a7mPUhvUiQM9AspKzJLR9mU7wy+P4e43153s6YOPDLZnQ4WW3nAT64mBTN kr/UH0QBHAZa72MpZ/ZtdzLLPF+DLvr7i6g0p93rZsMGSntVAihCqxQ/y/1S398H5aJJ S/dpE/sQcWuJ8sjJnxlZdAAG698UeTKVTvfDTku9aqF83T0sqKHM2CqJoiuhvTFys4OI 1mb7ACjjdRkvTR5FT4CnVea33wCr7zPYcwsWS92KaiaEVq2toH+QI+3ZgJhIRKY6XzGK h1KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723617465; x=1724222265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S50gDP85bfIUkvmV9LMgIBOxA9ssCMFmf5fjm28/XhI=; b=AuPC1Fg9W7cWPOKWUqQal4h4Y2jBobjsYW5EPcwpPPn7CypsareyfdYJe8RPnlyVTi 1qqS4BrU7OzNoJVIoeaFGsFWflz+Zpscp8RKhXXi5/N/VDUUArDSjc3TrDoIjCUAyRmQ 8t59hOx0IiUCx2MkSA6gYxknWXPVyXiJKwS154C1Lo4rjxwVRk9NMfGoPjMN9JBtq6+K g6j9qprDspio/SJnIkk90cJxFfZ6jKsF4qSgyPyfTV3u/dYTC9rOUGYyVaegQmJ3SuCn AuVHUuS4BtDO6ms5mDXyNUorf5nJ26NRZyQGzof4V7wx5xnJ1XrpILwQdG+9S08Q7dcm VPbA== X-Gm-Message-State: AOJu0YxrZxoHvd6Wbv1ORnPr6a/+YX76KNYdso+5FCVzG1jTxO/W5ZIG AQyhGF9Ty6wDDuBNix7hfOJlm79fdomlr6sW130hH4yrw7pEn9GBSr8S5kMq X-Google-Smtp-Source: AGHT+IG9LUngPYZx4GhHUe5IH3IN8L/mM+rRy+sFsEOV2UtuA2Rr7OOAgnh2kagbnDuVW3/FTN8i7w== X-Received: by 2002:a05:6402:2789:b0:5a2:5bd2:ca50 with SMTP id 4fb4d7f45d1cf-5bea1cac6d8mr1059491a12.25.1723617464730; Tue, 13 Aug 2024 23:37:44 -0700 (PDT) Received: from noahgold-desk.. ([45.83.220.204]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5dfdb0sm3577748a12.71.2024.08.13.23.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 23:37:44 -0700 (PDT) From: Noah Goldstein To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, hjl.tools@gmail.com, carlos@systemhalted.org Subject: [PATCH v3 1/2] x86: Use `Avoid_Non_Temporal_Memset` to control non-temporal path Date: Wed, 14 Aug 2024 14:37:30 +0800 Message-Id: <20240814063731.3014055-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813185714.2999710-1-goldstein.w.n@gmail.com> References: <20240813185714.2999710-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org This is just a refactor and there should be no behavioral change from this commit. The goal is to make `Avoid_Non_Temporal_Memset` a more universal knob for controlling whether we use non-temporal memset rather than having extra logic based on vendor. Reviewed-by: H.J. Lu --- sysdeps/x86/cpu-features.c | 16 ++++++++++++++++ sysdeps/x86/dl-cacheinfo.h | 15 +++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 18ed008040..a4786d23c7 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -756,6 +756,12 @@ init_cpu_features (struct cpu_features *cpu_features) unsigned int stepping = 0; enum cpu_features_kind kind; + /* Default is avoid non-temporal memset for non Intel/AMD hardware. This is, + as of writing this, we only have benchmarks indicatings it profitability + on Intel/AMD. */ + cpu_features->preferred[index_arch_Avoid_Non_Temporal_Memset] + |= bit_arch_Avoid_Non_Temporal_Memset; + cpu_features->cachesize_non_temporal_divisor = 4; #if !HAS_CPUID if (__get_cpuid_max (0, 0) == 0) @@ -781,6 +787,11 @@ init_cpu_features (struct cpu_features *cpu_features) update_active (cpu_features); + /* Benchmarks indicate non-temporal memset can be profitable on Intel + hardware. */ + cpu_features->preferred[index_arch_Avoid_Non_Temporal_Memset] + &= ~bit_arch_Avoid_Non_Temporal_Memset; + if (family == 0x06) { model += extended_model; @@ -992,6 +1003,11 @@ https://www.intel.com/content/www/us/en/support/articles/000059422/processors.ht ecx = cpu_features->features[CPUID_INDEX_1].cpuid.ecx; + /* Benchmarks indicate non-temporal memset can be profitable on AMD + hardware. */ + cpu_features->preferred[index_arch_Avoid_Non_Temporal_Memset] + &= ~bit_arch_Avoid_Non_Temporal_Memset; + if (CPU_FEATURE_USABLE_P (cpu_features, AVX)) { /* Since the FMA4 bit is in CPUID_INDEX_80000001 and diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h index a1c03b8903..3d0c8d43b8 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -988,14 +988,6 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) if (CPU_FEATURE_USABLE_P (cpu_features, FSRM)) rep_movsb_threshold = 2112; - /* Non-temporal stores are more performant on Intel and AMD hardware above - non_temporal_threshold. Enable this for both Intel and AMD hardware. */ - unsigned long int memset_non_temporal_threshold = SIZE_MAX; - if (!CPU_FEATURES_ARCH_P (cpu_features, Avoid_Non_Temporal_Memset) - && (cpu_features->basic.kind == arch_kind_intel - || cpu_features->basic.kind == arch_kind_amd)) - memset_non_temporal_threshold = non_temporal_threshold; - /* For AMD CPUs that support ERMS (Zen3+), REP MOVSB is in a lot of cases slower than the vectorized path (and for some alignments, it is really slow, check BZ #30994). */ @@ -1017,6 +1009,13 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) if (tunable_size != 0) shared = tunable_size; + /* Non-temporal stores are more performant on some hardware above + non_temporal_threshold. Currently Prefer_Non_Temporal is set for for both + Intel and AMD hardware. */ + unsigned long int memset_non_temporal_threshold = SIZE_MAX; + if (!CPU_FEATURES_ARCH_P (cpu_features, Avoid_Non_Temporal_Memset)) + memset_non_temporal_threshold = non_temporal_threshold; + tunable_size = TUNABLE_GET (x86_non_temporal_threshold, long int, NULL); if (tunable_size > minimum_non_temporal_threshold && tunable_size <= maximum_non_temporal_threshold)