From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id AF2431F8C6 for ; Tue, 27 Jul 2021 02:16:18 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB28A3951413 for ; Tue, 27 Jul 2021 02:16:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB28A3951413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627352177; bh=3rGtqFK9+r/6jf5BjoOSuIf6h9NEfJTgC8FLAQecxcY=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YS2Gy2HXw2pq4yfSL5uvicZkatwYbp/K4GMLZPqSDIrXpIELrIIpOZc64EiMdg+4D yJXETrF5AYnSmJ4NZt9d2429YhMW5AzAA+yT+0jtXdPaYPrtJmp4EBESbe+mGx2H0V l/xGYRn5j155tDccaY44MZmByKMlHEwoGjECWwcA= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 25F77383D820 for ; Tue, 27 Jul 2021 02:15:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 25F77383D820 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-CGg5MCrWOKmKM5HzuBAmOg-1; Mon, 26 Jul 2021 22:15:56 -0400 X-MC-Unique: CGg5MCrWOKmKM5HzuBAmOg-1 Received: by mail-qk1-f197.google.com with SMTP id 4-20020a3709040000b02903b854c43335so10405251qkj.21 for ; Mon, 26 Jul 2021 19:15:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=3rGtqFK9+r/6jf5BjoOSuIf6h9NEfJTgC8FLAQecxcY=; b=Nw3NcPi3ii2NcZlBnih2/7VpvnF/4A5n0NZ3AMLiV3m4XoAEh06BTGkEIqgFL/Lxl4 A/y5WMaGGWkbQDODuyNhjR1yrL9JJ+h26QlZ7jRuhTM6och67lGzjjDaSUEewRDnwAEg S70vyUuxvgcVHMDTO4e0AVQQ5VaahwqKBLL0vos2GLWAaaB7u65J83YI8WO/Lnm1NY8H tpFDIwzzBq6LuMXYR2o/xSiZC21+MwjFALeFhKO2xEQmQJk84IxzXENQJKXm8rko0R3l nHviGVpDEmE4ylVV3ZLYFXbrowtgvNauSHAXpBnTREyvD+yU0juEVDNqk66oPlnjkh6m mJww== X-Gm-Message-State: AOAM532WQ8JVKeBl9xrMQt1LSiQP/oCCFsVsh1DXG9X4zmhzIxQ5y5oa 13gVpvmwVkzILC04+sQ/QxSyBpLJL1dLx8oWwjDvndCQ9tdgiXxAheyLV0XuFkETpjL1AdKwqxf Qc0fpTZf9fpqw0LolyJGbDqzxskHGQT9PlwlnPTs15tKWBVUswGAdQriwtE77DJmZFVZvrA== X-Received: by 2002:a05:620a:b81:: with SMTP id k1mr18063692qkh.119.1627352155928; Mon, 26 Jul 2021 19:15:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzowA0a0xambJ63K5b77/WBXwfKDBer0ZIczhRVcQ85iDxJff91mkutwZwgMzvrsGEkTaymiQ== X-Received: by 2002:a05:620a:b81:: with SMTP id k1mr18063681qkh.119.1627352155705; Mon, 26 Jul 2021 19:15:55 -0700 (PDT) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id w26sm938838qki.6.2021.07.26.19.15.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Jul 2021 19:15:55 -0700 (PDT) Subject: Re: [PATCH] x86-64: Add Avoid_Short_Distance_REP_MOVSB To: "H.J. Lu" , libc-alpha@sourceware.org References: <20210726120055.1089971-1-hjl.tools@gmail.com> Organization: Red Hat Message-ID: Date: Mon, 26 Jul 2021 22:15:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210726120055.1089971-1-hjl.tools@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , From: Carlos O'Donell via Libc-alpha Reply-To: Carlos O'Donell Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On 7/26/21 8:00 AM, H.J. Lu via Libc-alpha wrote: > commit 3ec5d83d2a237d39e7fd6ef7a0bc8ac4c171a4a5 > Author: H.J. Lu > Date: Sat Jan 25 14:19:40 2020 -0800 > > x86-64: Avoid rep movsb with short distance [BZ #27130] > introduced some regressions on Intel processors without Fast Short REP > MOV (FSRM). Add Avoid_Short_Distance_REP_MOVSB to avoid rep movsb with > short distance only on Intel processors with FSRM. bench-memmove-large > on Skylake server shows that cycles of __memmove_evex_unaligned_erms are > improved for the following data size: > > before after Improvement > length=4127, align1=3, align2=0: 479.38 343.00 28% > length=4223, align1=9, align2=5: 405.62 335.50 17% > length=8223, align1=3, align2=0: 786.12 495.00 37% > length=8319, align1=9, align2=5: 256.69 170.38 33% > length=16415, align1=3, align2=0: 1436.88 839.50 41% > length=16511, align1=9, align2=5: 1375.50 840.62 39% > length=32799, align1=3, align2=0: 2890.00 1850.62 36% > length=32895, align1=9, align2=5: 2891.38 1948.62 32% > > There are no regression on Ice Lake server. At this point we're waiting on Noah to provide feedback on the performance results given the alignment nop insertion you provided as a follow-up patch (unless you can confirm this yourself). Looking forward to a v2 the incorporates the alignment fix (pending Noah's comments), and my suggestions below. > --- > sysdeps/x86/cacheinfo.h | 7 +++++++ > sysdeps/x86/cpu-features.c | 5 +++++ > .../x86/include/cpu-features-preferred_feature_index_1.def | 1 + > sysdeps/x86/sysdep.h | 3 +++ > sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S | 5 +++++ > 5 files changed, 21 insertions(+) > > diff --git a/sysdeps/x86/cacheinfo.h b/sysdeps/x86/cacheinfo.h > index eba8dbc4a6..174ea38f5b 100644 > --- a/sysdeps/x86/cacheinfo.h > +++ b/sysdeps/x86/cacheinfo.h > @@ -49,6 +49,9 @@ 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; > > +/* String/memory function control. */ > +int __x86_string_control attribute_hidden; Please expand comment. Suggest: /* A bit-wise OR of string/memory requirements for optimal performance e.g. X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB. These bits are used at runtime to tune implementation behavior. */ int __x86_string_control attribute_hidden; > + > static void > init_cacheinfo (void) > { > @@ -71,5 +74,9 @@ 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; > + > + if (CPU_FEATURES_ARCH_P (cpu_features, Avoid_Short_Distance_REP_MOVSB)) > + __x86_string_control > + |= X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB; OK. > } > #endif > diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c > index 706a172ba9..645bba6314 100644 > --- a/sysdeps/x86/cpu-features.c > +++ b/sysdeps/x86/cpu-features.c > @@ -555,6 +555,11 @@ init_cpu_features (struct cpu_features *cpu_features) > cpu_features->preferred[index_arch_Prefer_AVX2_STRCMP] > |= bit_arch_Prefer_AVX2_STRCMP; > } > + > + /* Avoid avoid short distance REP MOVSB on processor with FSRM. */ > + if (CPU_FEATURES_CPU_P (cpu_features, FSRM)) > + cpu_features->preferred[index_arch_Avoid_Short_Distance_REP_MOVSB] > + |= bit_arch_Avoid_Short_Distance_REP_MOVSB; OK. > } > /* This spells out "AuthenticAMD" or "HygonGenuine". */ > else if ((ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) > diff --git a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def > index 133aab19f1..d7c93f00c5 100644 > --- a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def > +++ b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def > @@ -33,3 +33,4 @@ BIT (Prefer_No_AVX512) > BIT (MathVec_Prefer_No_AVX512) > BIT (Prefer_FSRM) > BIT (Prefer_AVX2_STRCMP) > +BIT (Avoid_Short_Distance_REP_MOVSB) OK. > diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h > index 51c069bfe1..35cb90d507 100644 > --- a/sysdeps/x86/sysdep.h > +++ b/sysdeps/x86/sysdep.h > @@ -57,6 +57,9 @@ enum cf_protection_level > #define STATE_SAVE_MASK \ > ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7)) > Suggest adding: /* Constants for bits in __x86_string_control: */ > +/* Avoid short distance REP MOVSB. */ > +#define X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB (1 << 0) OK. > + > #ifdef __ASSEMBLER__ > > /* Syntactic details of assembler. */ > diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S > index a783da5de2..9f02624375 100644 > --- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S > +++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S > @@ -325,12 +325,16 @@ L(movsb): > /* Avoid slow backward REP MOVSB. */ > jb L(more_8x_vec_backward) > # if AVOID_SHORT_DISTANCE_REP_MOVSB > + andl $X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB, __x86_string_control(%rip) > + jz 3f OK. > movq %rdi, %rcx > subq %rsi, %rcx > jmp 2f > # endif > 1: > # if AVOID_SHORT_DISTANCE_REP_MOVSB > + andl $X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB, __x86_string_control(%rip) > + jz 3f OK. > movq %rsi, %rcx > subq %rdi, %rcx > 2: > @@ -338,6 +342,7 @@ L(movsb): > is N*4GB + [1..63] with N >= 0. */ > cmpl $63, %ecx > jbe L(more_2x_vec) /* Avoid "rep movsb" if ECX <= 63. */ > +3: OK. > # endif > mov %RDX_LP, %RCX_LP > rep movsb > -- Cheers, Carlos.