From patchwork Fri Jan 22 10:18:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: develop--- via Libc-alpha X-Patchwork-Id: 41792 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 75DFE398BC3D; Fri, 22 Jan 2021 10:19:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75DFE398BC3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611310755; bh=bevu45GuG+DcUUp3jyRA9AfAr8jjs/whlSEVYBdakyU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=k8O6da7VzQ32z82TEzBxwloHF84hbZ67BWCtBlfaR1Rx00T69zhCzEn8jScQz91kR eDYdtfgw+/a1+7rGDM/TFbtXcHHXDW8n8kxtkzGvRKuOYnxA0B6T1Su3uCZoV9/jK0 JpLGhcE9JT6O16uk3aghwopAQszLyolJC57gv698= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2051.outbound.protection.outlook.com [40.107.236.51]) by sourceware.org (Postfix) with ESMTPS id 94095398B88A for ; Fri, 22 Jan 2021 10:19:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 94095398B88A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CRgjjbNiFDuzGdii4Fw/vDSti/qTOrlt4dMAYU8yBHbcOhjx/8ukUlpxAgaEZyeKvIaRGFJoTH1MR+unABTG1aYfiCrADO8spHSB49y7v4jsmO/5brO5pxBskr6VWEkxfqisdzcCKWW+8V99fcRVvx43nzjcsXD++xtoTM8zzfwxYequND6/FzwVDlg9kLBRqhsQoc3PyMbZNqKaxB6+j4i5dg+j2N32VI16cJsBe7JLUUJPncR8dPSddjs1e8FSA/mXWb1DLQApm4oPd2O1UiZnSXmoHCR1rT4m+dNnN2k/G1BegAIZ7JQRBUZmUzZnvkKmjXnR/gymJEC4DJCXEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bevu45GuG+DcUUp3jyRA9AfAr8jjs/whlSEVYBdakyU=; b=ngkeUlm/D+jl2vIX62nllbXYhiemW+3x79ZZI5Czngwou9g6lV5In48gjUUAVjAZ0GoEgK7/oDfjHDpHifaVzL/5D12KjrmB3zMx84MFv+VP1nz0VPnmwVgKyeArTYM7pC+voRpp4rmTPIiOLyZ8IWKGRcXYcL9EdlQOrj0eli9BxwDHmOfDtZIw2FzloYm+n+IQvAGxXatcfjHCNGcg8sQhm3UzfGaVyLS5d8Of2oGvU+BRH5xJBa7GY6i7YpRejTg1eYNGnb5u7CK43ca699DNEQQ7nzeCYjHGP7ZNasizH7rURCIjLPS8VgIledgKjRQnsWSq33tTNoaSaIK20A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from BN6PR1201MB0081.namprd12.prod.outlook.com (2603:10b6:405:4f::12) by BN8PR12MB3601.namprd12.prod.outlook.com (2603:10b6:408:46::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Fri, 22 Jan 2021 10:19:11 +0000 Received: from BN6PR1201MB0081.namprd12.prod.outlook.com ([fe80::20fa:a1a2:9e7d:1370]) by BN6PR1201MB0081.namprd12.prod.outlook.com ([fe80::20fa:a1a2:9e7d:1370%11]) with mapi id 15.20.3742.014; Fri, 22 Jan 2021 10:19:10 +0000 To: fweimer@redhat.com Subject: [PATCH] x86: Adding an upper bound for Enhanced REP MOVSB. Date: Fri, 22 Jan 2021 15:48:50 +0530 Message-Id: <20210122101850.3028846-1-sajan.karumanchi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <87wnwamax7.fsf@oldenburg.str.redhat.com> References: <87wnwamax7.fsf@oldenburg.str.redhat.com> X-Originating-IP: [165.204.156.251] X-ClientProxiedBy: MA1PR0101CA0027.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::13) To BN6PR1201MB0081.namprd12.prod.outlook.com (2603:10b6:405:4f::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from amd.com (165.204.156.251) by MA1PR0101CA0027.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Fri, 22 Jan 2021 10:19:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f2f2e9c0-3551-4f7c-e7f3-08d8bebf28c2 X-MS-TrafficTypeDiagnostic: BN8PR12MB3601: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RJ+322FN2mUpIXD27SvbxttBRJRSC0yWKaLOZU8rk/oEimlcOuEcZjxSe9i5htmICjJDR0AFhTcTxlNhNKEvF9GXBTj3XCFgS6DXDx1J8q06x8M7y8jdpb2ZashfxbL+uaRRrI4zQhgGZOeuJ9/xKT7INNgBASCCbLTmqlSZM5+S2JTelJpJxlkRWRMtIXdh88LLuBD/1xGzoXCTgRaXuFsl4QCYD6z8jx22QZsw8XM8BdYn3vZVqQFRyxr+owkZe3qsj/rmGLYIEILE4phQaATmNvW77B6fkqAbGEa0l3p2FGewOgxmJVjk7804zayCkV3Vjip8g2SGEQaXp9m5F+kwjf4nUR90HjezsqOdHyfORcPogI8rldPKXMSoBKoD0TP94XIq+5P/W7cj1BSdKyATT76Yr181ZibxeACymRNJ1snNfia/lkz3nLsK9zB/6LoLWhQ0n6pes/UETMnG45pdSa5uzYBhkzyi6Ucz+6rz8fM4bw/0iwTZk7LkonFSiknLEXMNLGRWr5Pxts/JQg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR1201MB0081.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(136003)(39860400002)(396003)(346002)(83380400001)(54906003)(5660300002)(55016002)(66556008)(956004)(2906002)(66946007)(36756003)(8886007)(66476007)(1076003)(6916009)(86362001)(316002)(52116002)(8676002)(186003)(7696005)(26005)(2616005)(478600001)(8936002)(16526019)(9686003)(4326008)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: I494fodqcuU/QPFSMN0eVkNpmY3RwUjaeMqPwYgjBaTM8VlT78SFtZkHfOAHK60JpuBjlkv1H1zT4W0/NBFq0Hssc+Hr3L9l6DWF+rFbdtqnkQTCY3f0j+tVC8l3JVhmDP8M05TMXg06D7zOWOH0JLdcixgJfGkRaP6JcsNGZRn/u9t7vbkH7bkhNF0XTtQDNxazWiKGYnTVRYEyxYsNDgUPjpgsdCkfCCebYnvO0bhsG50RxD/B6rCmDZgaIq/Ne7bte7MP3AXsW5P/53h40NDK5Q9uB4F8CM6+JUYfitC5/yuT/ues1zHKQfdWISu1ITEQ103EluiY4ODjMDrMcp+nIXLxyaUj374D9PV+mUIxM86qbPuDmTuL1b9ALHXNRp/ZaKTEqrvM7ZHD36DMUd8av7QC6Y2Z3WXsEHpbt/bK1WlsBoN7/yKBaps/PVY0ylMKATfW0LlpaEVTatJ32mLGzP+QxFyVsMRC/H96xRrIUz9I4qON5q8aLppssTyStUV7QlrLhwMfR9GulvLurqhJ+rVcInJ32qkRKwhNnxzV8OylHRj+/4JcP9c/Ly6t84cxn89MKGKkt/GXSzv2IZ1A0O6OS9hOClSJBRAS8sQkVsBhz4LdsykcLCI5kAhyQkwC7icdgsOyauqhE/E34c5qeKnyEk4w+0WY9fq0QMnskBDUeUUf8zj0dGZ+y50xqEH0zwdB/wp9mnegbOuP34eIgMO6Hogk5lYqTU8LAEgLPMy6kE4cSJRSAWD4S9u9ayVLixzx7F08fZ9DAT+rd55W0iWKouPED5hz0I4hhrm8cq6OPaP8qx1j5Oqozm6fuGqSn42suWuOyK1MPkN7HrHGxN9qMc1KMLkbJWff9XgxMFXCjng/Q+TywoPzyN/2aXQ64al7+Gz7Y2k2Szv54j9UF3SMrW2gyc4nlZFCsYoyC9z/ms9dq6N3osGgWAtbxrex55XjhDVlEMc6ZnrQFCSzoIjQsIAB6mHDYBql9kltTUuq0C+y02Ya/8tGy3Ym X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2f2e9c0-3551-4f7c-e7f3-08d8bebf28c2 X-MS-Exchange-CrossTenant-AuthSource: BN6PR1201MB0081.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2021 10:19:10.8076 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qEACZ+EYS5IGD+4Rm+4Fvk16xcjbZFpvETl7/jlXt0/iFHGIG75F3lq41M+m8MKKaZWJxKM2h0SbYiwyG7j72Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3601 X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "sajan.karumanchi--- via Libc-alpha" From: develop--- via Libc-alpha Reply-To: sajan.karumanchi@amd.com Cc: Sajan Karumanchi , Premachandra Mallappa , libc-alpha@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Sajan Karumanchi In the process of optimizing memcpy for AMD machines, we have found the vector move operations are outperforming enhanced REP MOVSB for data transfers above the L2 cache size on Zen3 architectures. To handle this use case, we are adding an upper bound parameter on enhanced REP MOVSB:'__x86_rep_movsb_stop_threshold'. As per large-bench results, we are configuring this parameter to the L2 cache size for AMD machines and applicable from Zen3 architecture supporting the ERMS feature. For architectures other than AMD, it is the computed value of non-temporal threshold parameter. Reviewed-by: Premachandra Mallappa --- sysdeps/x86/cacheinfo.h | 4 ++++ sysdeps/x86/dl-cacheinfo.h | 15 ++++++++++++++- sysdeps/x86/include/cpu-features.h | 2 ++ .../x86_64/multiarch/memmove-vec-unaligned-erms.S | 7 +++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sysdeps/x86/cacheinfo.h b/sysdeps/x86/cacheinfo.h index 68c253542f..0f0ca7c08c 100644 --- a/sysdeps/x86/cacheinfo.h +++ b/sysdeps/x86/cacheinfo.h @@ -54,6 +54,9 @@ long int __x86_rep_movsb_threshold attribute_hidden = 2048; /* Threshold to use Enhanced REP STOSB. */ long int __x86_rep_stosb_threshold attribute_hidden = 2048; +/* Threshold to stop using Enhanced REP MOVSB. */ +long int __x86_rep_movsb_stop_threshold attribute_hidden; + static void init_cacheinfo (void) { @@ -79,5 +82,6 @@ init_cacheinfo (void) __x86_rep_movsb_threshold = cpu_features->rep_movsb_threshold; __x86_rep_stosb_threshold = cpu_features->rep_stosb_threshold; + __x86_rep_movsb_stop_threshold = cpu_features->rep_movsb_stop_threshold; } #endif diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h index a31fa0783a..374ba82467 100644 --- a/sysdeps/x86/dl-cacheinfo.h +++ b/sysdeps/x86/dl-cacheinfo.h @@ -704,7 +704,7 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) int max_cpuid_ex; long int data = -1; long int shared = -1; - long int core; + long int core = -1; unsigned int threads = 0; unsigned long int level1_icache_size = -1; unsigned long int level1_dcache_size = -1; @@ -886,6 +886,18 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) #endif } + unsigned long int rep_movsb_stop_threshold; + /* ERMS feature is implemented from AMD Zen3 architecture and it is + performing poorly for data above L2 cache size. Henceforth, adding + an upper bound threshold parameter to limit the usage of Enhanced + REP MOVSB operations and setting its value to L2 cache size. */ + if (cpu_features->basic.kind == arch_kind_amd) + rep_movsb_stop_threshold = core; + /* Setting the upper bound of ERMS to the computed value of + non-temporal threshold for architectures other than AMD. */ + else + rep_movsb_stop_threshold = non_temporal_threshold; + /* The default threshold to use Enhanced REP STOSB. */ unsigned long int rep_stosb_threshold = 2048; @@ -935,4 +947,5 @@ dl_init_cacheinfo (struct cpu_features *cpu_features) cpu_features->non_temporal_threshold = non_temporal_threshold; cpu_features->rep_movsb_threshold = rep_movsb_threshold; cpu_features->rep_stosb_threshold = rep_stosb_threshold; + cpu_features->rep_movsb_stop_threshold = rep_movsb_stop_threshold; } diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h index 624736b40e..475e877294 100644 --- a/sysdeps/x86/include/cpu-features.h +++ b/sysdeps/x86/include/cpu-features.h @@ -870,6 +870,8 @@ struct cpu_features unsigned long int non_temporal_threshold; /* Threshold to use "rep movsb". */ unsigned long int rep_movsb_threshold; + /* Threshold to stop using "rep movsb". */ + unsigned long int rep_movsb_stop_threshold; /* Threshold to use "rep stosb". */ unsigned long int rep_stosb_threshold; /* _SC_LEVEL1_ICACHE_SIZE. */ diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S index 0980c95378..50bb1fccb2 100644 --- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S +++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S @@ -30,7 +30,10 @@ load and aligned store. Load the last 4 * VEC and first VEC before the loop and store them after the loop to support overlapping addresses. - 6. If size >= __x86_shared_non_temporal_threshold and there is no + 6. On machines with ERMS feature, if size greater than equal or to + __x86_rep_movsb_threshold and less than + __x86_rep_movsb_stop_threshold, then REP MOVSB will be used. + 7. If size >= __x86_shared_non_temporal_threshold and there is no overlap between destination and source, use non-temporal store instead of aligned store. */ @@ -240,7 +243,7 @@ L(return): ret L(movsb): - cmp __x86_shared_non_temporal_threshold(%rip), %RDX_LP + cmp __x86_rep_movsb_stop_threshold(%rip), %RDX_LP jae L(more_8x_vec) cmpq %rsi, %rdi jb 1f