From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 183383858298; Fri, 27 Oct 2023 12:39:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183383858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1698410350; bh=oAxzGVKXNmL7I/bdXICI+8clghnqp8kqyUCc67QiAIM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=l7B+aQ1WBtYLvSXPS4NzS/WpVgwlCqAtF4DoDbU9FUTV12Zvgrkf26Hgwb0jw0cTU Mi9x8WYpPavE7iXw+ZTZXhqJexKnlPbEqI5i8UuiLest5ym2rM4Ozo6WVDWy70AsK/ hG3dQkkD4X8H4PE4aKsU09B8gzXYotTPhSPB78KU= From: "adhemerval.zanella at linaro dot org" To: glibc-bugs@sourceware.org Subject: [Bug string/30994] REP MOVSB performance suffers from page aliasing on Zen 4 Date: Fri, 27 Oct 2023 12:39:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: string X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: adhemerval.zanella at linaro dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: security- X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30994 Adhemerval Zanella changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adhemerval.zanella at lina= ro dot o | |rg --- Comment #6 from Adhemerval Zanella --- I have access to a Zen3 code (5900X) and I can confirm that using REP MOVSB seems to be always worse than vector instructions. ERMS is used for sizes between 2112 (rep_movsb_threshold) and 524288 (rep_movsb_stop_threshold or = the L2 size for Zen3) and the '-S 0 -D 1' performance really seems to be a microcode since I don't see similar performance difference with other alignments. On Zen3 with REP MOVSB I see: $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 84.2448 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 `seq = -s' ' 0 2 23` 506.099 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 `seq = -s' ' 0 23` 990.845 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 57.1122 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 `seq -s' ' 0 2 23` 325.409 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 `seq -s' ' 0 23` 510.87 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 4.43104 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 `seq= -s' ' 0 2 23` 22.4551 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 `seq= -s' ' 0 23` 40.4088 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 4.34671 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 `s= eq -s' ' 0 2 23` 22.0829 GB/s $ ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 `s= eq -s' ' 0 23` While with vectorized instructions I see: $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 124.183 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 `seq -s' ' 0 2 23` 773.696 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 0 `seq -s' ' 0 23` 1413.02 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 58.3212 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 `seq -s' ' 0 2 23` 322.583 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 0 `seq -s' ' 0 23` 506.116 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 121.872 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 `seq -s' ' 0 2 23` 717.717 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 2113 -p 100000 -D 15 `seq -s' ' 0 23` 1318.17 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 58.5352 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 `seq -s' ' 0 2 23` 325.996 GB/s $ GLIBC_TUNABLES=3Dglibc.cpu.x86_rep_movsb_threshold=3D1000000 ./testrun.sh ./memcpy_loop -t mmap -f memcpy -b 524287 -p 100000 -D 15 `seq -s' ' 0 23` 498.552 GB/s So it seems there in gain in using REP MOVSB on Zen3/Zen4, specially on the size is was supposed to be better. glibc 2.34 added a fix from AMD (6e02b3e9327b7dbb063958d2b124b64fcb4bbe3f), where the assumption is ERMS performs poorly on data above L2 cache size so REP MOVSB is limited to L2 c= ache size (from 2113 to 524287), but I think AMD engineers did not really evalua= ted that ERM is indeed better than vectorized instruction. And I think BZ#30995 is the same issue, since __memcpy_avx512_unaligned_erms uses the same tunable to decide whether to use ERMS. I have created a patch that just disable ERMS usage on AMD cores [1], can you check if it improves performance on Zen4 as well? Also, I have notices that memset is also showing subpar performance with ER= MS and I also disable it on my branch. [1] https://sourceware.org/git/?p=3Dglibc.git;a=3Dshortlog;h=3Drefs/heads/azane= lla/bz30944-memcpy-zen --=20 You are receiving this mail because: You are on the CC list for the bug.=