From patchwork Mon Aug 12 06:48:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feifei Wang X-Patchwork-Id: 95655 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 2E9A43858402 for ; Mon, 12 Aug 2024 06:50:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mailgw2.hygon.cn (unknown [110.188.70.11]) by sourceware.org (Postfix) with ESMTP id 9BC303858D35 for ; Mon, 12 Aug 2024 06:48:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BC303858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hygon.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hygon.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9BC303858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=110.188.70.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445330; cv=none; b=A6Qgs/IxxQ+BsMCMMJjtEhdHZRKREZKVFB0Z8eNxOc6xeVfIuxB94D9/mXPxApiQ2P8eZnG1mb6uBZZN1msEnevSje+QavD9/oZjVZov3wV+qFihIegBzLs8KAK/K8Af8HkpsVkitXfLyq4ZiooLc7Z5a/R6+RKF/H8tMe2aqE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445330; c=relaxed/simple; bh=WKIwbr9Thvmn7/MhRE56BlnUzZv2ckf744KQdg+gUtY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iaLrTnlMw4DaF031kIosVE4hLqKKEWrfoirojU3GBIRJvFiLM8jlwztHRABsfDovOx6rzs53ic7xIrKLKvuhwMKdBAuBVeYAJANKg5aQ6bcbLWshRKP2ffSeRrLPugEE7dlxnAVAeoLU6e2iSNCnDZw8QJx2HKnycCMdpabtgMw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from maildlp1.hygon.cn (unknown [172.23.18.60]) by mailgw2.hygon.cn (Postfix) with ESMTP id 75B713004C95; Mon, 12 Aug 2024 14:44:09 +0800 (CST) Received: from cncheex01.Hygon.cn (unknown [172.23.18.10]) by maildlp1.hygon.cn (Postfix) with ESMTPS id A19984B6C; Mon, 12 Aug 2024 14:48:35 +0800 (CST) Received: from trace.hygon.cn (172.23.18.45) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 12 Aug 2024 14:48:38 +0800 From: Feifei Wang To: CC: , , , , , Subject: [RFC PATCH 1/3] x86: Add new architecture type for Hygon processors Date: Mon, 12 Aug 2024 14:48:23 +0800 Message-ID: <1723445305-99403-2-git-send-email-wangfeifei@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> References: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> MIME-Version: 1.0 X-Originating-IP: [172.23.18.45] X-ClientProxiedBy: cncheex01.Hygon.cn (172.23.18.10) To cncheex01.Hygon.cn (172.23.18.10) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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~patchwork=sourceware.org@sourceware.org Add a new architecture type arch_kind_hygon to spilt Hygon branch from AMD. This is to facilitate the Hygon processors to make settings that are suitable for its own characteristics. Signed-off-by: Feifei Wang Reviewed-by: Jing Li --- sysdeps/x86/cpu-features.c | 19 ++++++++++++++++--- sysdeps/x86/include/cpu-features.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index c096dd390a..034dc28f64 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -974,9 +974,8 @@ https://www.intel.com/content/www/us/en/support/articles/000059422/processors.ht cpu_features->preferred[index_arch_Avoid_Short_Distance_REP_MOVSB] |= bit_arch_Avoid_Short_Distance_REP_MOVSB; } - /* This spells out "AuthenticAMD" or "HygonGenuine". */ - else if ((ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) - || (ebx == 0x6f677948 && ecx == 0x656e6975 && edx == 0x6e65476e)) + /* This spells out "AuthenticAMD". */ + else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) { unsigned int extended_model; @@ -1086,6 +1085,20 @@ https://www.intel.com/content/www/us/en/support/articles/000059422/processors.ht } } } + /* This spells out "HygonGenuine". */ + else if (ebx == 0x6f677948 && ecx == 0x656e6975 && edx == 0x6e65476e) + { + unsigned int extended_model; + + kind = arch_kind_hygon; + + get_common_indices (cpu_features, &family, &model, &extended_model, + &stepping); + + get_extended_indices (cpu_features); + + update_active (cpu_features); + } else { kind = arch_kind_other; diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h index aaae44f0e1..b8e790c8fd 100644 --- a/sysdeps/x86/include/cpu-features.h +++ b/sysdeps/x86/include/cpu-features.h @@ -881,6 +881,7 @@ enum cpu_features_kind arch_kind_intel, arch_kind_amd, arch_kind_zhaoxin, + arch_kind_hygon, arch_kind_other }; From patchwork Mon Aug 12 06:48:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feifei Wang X-Patchwork-Id: 95654 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 B5FB2385841E for ; Mon, 12 Aug 2024 06:49:58 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mailgw1.hygon.cn (unknown [110.188.70.11]) by sourceware.org (Postfix) with ESMTP id 904AA3858D34 for ; Mon, 12 Aug 2024 06:48:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 904AA3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hygon.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hygon.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 904AA3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=110.188.70.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445331; cv=none; b=nHe3jDR+pFwBiDi615MH09t5cAKq7n9AwEtZNbWSZmBTDBZxcWiJdhcgz6Y5phJZiF055WlSQECjXmBrUFAHUTvDoZGA75R+93gt38lgSMbXHOPZ8yuoEWx6J2bVs5vWPqRbGensXQAyzW8L1rUa1KCV25O9MCHnchnvygxV4iU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445331; c=relaxed/simple; bh=3k1psADoKYnPLK4M2KbrZotToqpjT+P8WRnxuFFbzfM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=k3nl/bL0ffM6DXqLCYmRe9iAWL4MEMJBnvGLN2OjOYUuf8WULCAlg1EYNPIJCqfeMSuJEVSR90rMIZLA9MS5BFWKCOAvduP0ZrYcM5Y4OUVGeI/MsYHeG+u67SviGPkLaaE+zcVleIKyMv3/3oOfUEHQ44b4iKhtv+Pg/5I6tCY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from maildlp2.hygon.cn (unknown [172.23.18.61]) by mailgw1.hygon.cn (Postfix) with ESMTP id 46CA6F99E; Mon, 12 Aug 2024 14:48:37 +0800 (CST) Received: from cncheex01.Hygon.cn (unknown [172.23.18.10]) by maildlp2.hygon.cn (Postfix) with ESMTPS id 85019352C6E8; Mon, 12 Aug 2024 14:39:41 +0800 (CST) Received: from trace.hygon.cn (172.23.18.45) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 12 Aug 2024 14:48:39 +0800 From: Feifei Wang To: CC: , , , , , Subject: [RFC PATCH 2/3] x86: Add cache information support for Hygon processors Date: Mon, 12 Aug 2024 14:48:24 +0800 Message-ID: <1723445305-99403-3-git-send-email-wangfeifei@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> References: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> MIME-Version: 1.0 X-Originating-IP: [172.23.18.45] X-ClientProxiedBy: cncheex01.Hygon.cn (172.23.18.10) To cncheex01.Hygon.cn (172.23.18.10) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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~patchwork=sourceware.org@sourceware.org Add hygon branch in dl_init_cacheinfo function to initialize cache size variables for hygon processors. In the meanwhile, add handle_hygon() function to get cache information. Signed-off-by: Feifei Wang Reviewed-by: Jing Li --- sysdeps/x86/dl-cacheinfo.h | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h index a1c03b8903..2d456ba91c 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -567,6 +567,48 @@ handle_zhaoxin (int name) return 0; } +static long int __attribute__ ((noinline)) +handle_hygon (int name) +{ + unsigned int eax; + unsigned int ebx; + unsigned int ecx; + unsigned int edx; + unsigned int count = 0x1; + + if (name >= _SC_LEVEL3_CACHE_SIZE) + count = 0x3; + else if (name >= _SC_LEVEL2_CACHE_SIZE) + count = 0x2; + else if (name >= _SC_LEVEL1_DCACHE_SIZE) + count = 0x0; + + /* Use __cpuid__ '0x8000_001D' to compute cache details. */ + __cpuid_count (0x8000001D, count, eax, ebx, ecx, edx); + + switch (name) + { + case _SC_LEVEL1_ICACHE_ASSOC: + case _SC_LEVEL1_DCACHE_ASSOC: + case _SC_LEVEL2_CACHE_ASSOC: + case _SC_LEVEL3_CACHE_ASSOC: + return ((ebx >> 22) & 0x3ff) + 1; + case _SC_LEVEL1_ICACHE_LINESIZE: + case _SC_LEVEL1_DCACHE_LINESIZE: + case _SC_LEVEL2_CACHE_LINESIZE: + case _SC_LEVEL3_CACHE_LINESIZE: + return (ebx & 0xfff) + 1; + case _SC_LEVEL1_ICACHE_SIZE: + case _SC_LEVEL1_DCACHE_SIZE: + case _SC_LEVEL2_CACHE_SIZE: + case _SC_LEVEL3_CACHE_SIZE: + return (((ebx >> 22) & 0x3ff) + 1) * ((ebx & 0xfff) + 1) * (ecx + 1); + default: + __builtin_unreachable (); + } + return -1; +} + static void get_common_cache_info (long int *shared_ptr, long int * shared_per_thread_ptr, unsigned int *threads_ptr, long int core) @@ -889,6 +931,24 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) shared_per_thread = shared; } + else if (cpu_features->basic.kind == arch_kind_hygon) + { + data = handle_hygon (_SC_LEVEL1_DCACHE_SIZE); + shared = handle_hygon (_SC_LEVEL3_CACHE_SIZE); + shared_per_thread = shared; + + level1_icache_size = handle_hygon (_SC_LEVEL1_ICACHE_SIZE); + level1_icache_linesize = handle_hygon (_SC_LEVEL1_ICACHE_LINESIZE); + level1_dcache_size = data; + level1_dcache_assoc = handle_hygon (_SC_LEVEL1_DCACHE_ASSOC); + level1_dcache_linesize = handle_hygon (_SC_LEVEL1_DCACHE_LINESIZE); + level2_cache_size = handle_hygon (_SC_LEVEL2_CACHE_SIZE);; + level2_cache_assoc = handle_hygon (_SC_LEVEL2_CACHE_ASSOC); + level2_cache_linesize = handle_hygon (_SC_LEVEL2_CACHE_LINESIZE); + level3_cache_size = shared; + level3_cache_assoc = handle_hygon (_SC_LEVEL3_CACHE_ASSOC); + level3_cache_linesize = handle_hygon (_SC_LEVEL3_CACHE_LINESIZE); + } cpu_features->level1_icache_size = level1_icache_size; cpu_features->level1_icache_linesize = level1_icache_linesize; From patchwork Mon Aug 12 06:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feifei Wang X-Patchwork-Id: 95653 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 667203858294 for ; Mon, 12 Aug 2024 06:49:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mailgw1.hygon.cn (unknown [110.188.70.11]) by sourceware.org (Postfix) with ESMTP id CB6CA3858D39 for ; Mon, 12 Aug 2024 06:48:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB6CA3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hygon.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hygon.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB6CA3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=110.188.70.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445331; cv=none; b=jPKZme5zhYMVsCFAAxlAmJlTiCcZK8WyXxuwJh7TQwDTQXhRFcbgjDULSQnFIdTzE0blOC5fcY9y0dvoyjPkPPlQJYJjokcHXMmL9IOsexJww7Ba4jDlqhehdUkPcXmgHxLT0bfoBA7pgY6hNq082XEhZXksHwAEUnZaWuU02wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723445331; c=relaxed/simple; bh=+wXHZIgbXhXu+IUi0jsx1DwJCnQurSL1FpkQdA9wvDM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bJJf1yqfv21mJI1Bmg16HUn5N7L1S7eV95PI4gSTN0tpNYuamhM4Qv9t7JZa05V6DfbAFitrxG2nbUNxCEvsvPh+QPUsBFpnEy/vs864nKYL9YoRBSOemnMah0Pm7NJupY9JheuXyF7ukiTgxuQU48oWMhRvKSniJKeleYlKRQU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from maildlp1.hygon.cn (unknown [172.23.18.60]) by mailgw1.hygon.cn (Postfix) with ESMTP id 79202F9A0; Mon, 12 Aug 2024 14:48:38 +0800 (CST) Received: from cncheex01.Hygon.cn (unknown [172.23.18.10]) by maildlp1.hygon.cn (Postfix) with ESMTPS id 66B711571; Mon, 12 Aug 2024 14:48:38 +0800 (CST) Received: from trace.hygon.cn (172.23.18.45) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 12 Aug 2024 14:48:41 +0800 From: Feifei Wang To: CC: , , , , , Subject: [RFC PATCH 3/3] x86: Enable non-temporal memset for Hygon processors Date: Mon, 12 Aug 2024 14:48:25 +0800 Message-ID: <1723445305-99403-4-git-send-email-wangfeifei@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> References: <1723445305-99403-1-git-send-email-wangfeifei@hygon.cn> MIME-Version: 1.0 X-Originating-IP: [172.23.18.45] X-ClientProxiedBy: cncheex01.Hygon.cn (172.23.18.10) To cncheex01.Hygon.cn (172.23.18.10) X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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~patchwork=sourceware.org@sourceware.org This patch is based on the following new flag patch: https://patchwork.sourceware.org/project/glibc/patch/20240811055619.2863839-1-goldstein.w.n@gmail.com/ After the new cpu-flag 'Prefer_Non_Temporal' is added in glibc, this patch can be enabled to access the non-temporal memset implementation for hygon processors. Test Results: thread: 1 memset store value: 0 hygon1 arch x86_memset_non_temporal_threshold = 8MB size new performance / old performance 128 byte(2x -4x vec case) 1 256 byte(4x - 8x vec case) 1 512 byte( > 8x loop case) 1 1MB 0.994 4MB 0.996 8MB 0.670 16MB 0.343 32MB 0.355 hygon2 arch x86_memset_non_temporal_threshold = 8MB size new performance / old performance 128 byte(2x -4x vec case) 1 256 byte(4x - 8x vec case) 0.653 512 byte( > 8x loop case) 0.713 1MB 1 4MB 0.887 8MB 1.312 16MB 0.822 32MB 0.830 hygon3 arch x86_memset_non_temporal_threshold = 8MB size new performance / old performance 128 byte(2x -4x vec case) 1 256 byte(4x - 8x vec case) 1 512 byte( > 8x loop case) 1 1MB 1 4MB 0.990 8MB 0.737 16MB 0.390 32MB 0.401 For hygon arch with this patch, no performance degradation on '2x - 8x branch case' when extra branch jump added. And with this patch, non-temporal stores can improve performance by 20% - 65%. Signed-off-by: Feifei Wang Reviewed-by: Jing Li --- sysdeps/x86/cpu-features.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 034dc28f64..cae26babc7 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -1098,6 +1098,12 @@ https://www.intel.com/content/www/us/en/support/articles/000059422/processors.ht get_extended_indices (cpu_features); update_active (cpu_features); + + /* Use Prefer_Non_Temporal flag to access the non-temporal + memset implementation due to ERMS is disable in Hygon + processors. */ + cpu_features->preferred[index_arch_Prefer_Non_Temporal] + |= (bit_arch_Prefer_Non_Temporal); } else {