From: Richard Henderson <richard.henderson@linaro.org>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: qemu-devel@nongnu.org, mmromanov@ispras.ru
Subject: Re: [PATCH v4 00/10] Optimize buffer_is_zero
Date: Thu, 15 Feb 2024 22:11:43 -1000 [thread overview]
Message-ID: <08ce9292-75a0-4092-a12e-9a12826847b0@linaro.org> (raw)
In-Reply-To: <aa9996fb-a5f8-25aa-96dd-48e4797967e1@ispras.ru>
On 2/15/24 13:37, Alexander Monakov wrote:
> Ah, I guess you might be running at low perf_event_paranoid setting that
> allows unprivileged sampling of kernel events? In our submissions the
> percentage was for perf_event_paranoid=2, i.e. relative to Qemu only,
> excluding kernel time under syscalls.
Ok. Eliminating kernel samples makes things easier to see.
But I still do not see a 40% reduction in runtime.
Just so we're on the same page:
> Retrieve IE11.Win7.VirtualBox.zip from
> https://archive.org/details/ie11.win7.virtualbox
> and use
>
> unzip -p IE11.Win7.VirtualBox.zip | tar xv
>
> to extract 'IE11 - Win7-disk001.vmdk'.
>
> (Mikhail used a different image when preparing the patch)
>
> On this image, I get 70% in buffer_zero_sse2 on a Sandy Bridge running
>
> qemu-img convert 'IE11 - Win7-disk001.vmdk' -O qcow2 /tmp/t.qcow2
With this, I see virtually all of the runtime in libz.so.
Therefore I converted this to raw first, to focus on the issue.
For avoidance of doubt:
$ ls -lsh test.raw && sha256sum test.raw
12G -rw-r--r-- 1 rth rth 40G Feb 15 21:14 test.raw
3b056d839952538fed42fa898c6063646f4fda1bf7ea0180fbb5f29d21fe8e80 test.raw
Host: 11th Gen Intel(R) Core(TM) i7-1195G7 @ 2.90GHz
Compiler: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
master:
57.48% qemu-img-m [.] buffer_zero_avx2
3.60% qemu-img-m [.] is_allocated_sectors.part.0
2.61% qemu-img-m [.] buffer_is_zero
63.69% -- total
v3:
48.86% qemu-img-v3 [.] is_allocated_sectors.part.0
3.79% qemu-img-v3 [.] buffer_zero_avx2
52.65% -- total
-17% -- reduction from master
v4:
54.60% qemu-img-v4 [.] buffer_is_zero_ge256
3.30% qemu-img-v4 [.] buffer_zero_avx2
3.17% qemu-img-v4 [.] is_allocated_sectors.part.0
61.07% -- total
-4% -- reduction from master
v4+:
46.65% qemu-img [.] is_allocated_sectors.part.0
3.49% qemu-img [.] buffer_zero_avx2
0.05% qemu-img [.] buffer_is_zero_ge256
50.19% -- total
-21% -- reduction from master
The v4+ puts the 3 byte test back inline, like in your v3.
Importantly, it must be as 3 short-circuting tests, where my v4 "simplified" this to (s |
m | e) != 0, on the assumption that the reduced number of branches would help.
Diving into perf, it becomes clear why:
57.36 │ cmpb $0x0,(%rbx)
4.02 │ ↓ jne 89
21.84 │ cmpb $0x0,0x1ff(%rbx)
0.64 │ ↓ jne 89
8.45 │ cmpb $0x0,0x100(%rbx)
0.26 │ ↓ jne 89
0.06 │ mov $0x200,%esi
│ mov %rbx,%rdi
0.07 │ → call buffer_is_zero_ge256
The three bytes are on 3 different cachelines. Judging by the relative percentages, it
would seem that the first byte alone eliminates slightly more than half of all blocks; the
last byte eliminates more than half again; the middle byte eliminates a fair fraction of
the rest. With the short-circuit, the extra cachelines are not touched.
This is so important that it should be spelled out in a comment.
With that settled, I guess we need to talk about how much the out-of-line implementation
matters at all. I'm thinking about writing a test/bench/bufferiszero, with all-zero
buffers of various sizes and alignments. With that it would be easier to talk about
whether any given implementation is is an improvement for that final 4% not eliminated by
the three bytes.
> (which does tell us that qemu-img is doing I/O inefficiently, it shouldn't
> need two seconds to read a fully cached 5 Gigabyte file)
Indeed!
r~
next prev parent reply other threads:[~2024-02-16 8:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 8:14 [PATCH v4 00/10] Optimize buffer_is_zero Richard Henderson
2024-02-15 8:14 ` [PATCH v4 01/10] util/bufferiszero: Remove SSE4.1 variant Richard Henderson
2024-02-15 8:14 ` [PATCH v4 02/10] util/bufferiszero: Remove AVX512 variant Richard Henderson
2024-02-15 8:14 ` [PATCH v4 03/10] util/bufferiszero: Reorganize for early test for acceleration Richard Henderson
2024-02-15 8:14 ` [PATCH v4 04/10] util/bufferiszero: Remove useless prefetches Richard Henderson
2024-02-15 8:14 ` [PATCH v4 05/10] util/bufferiszero: Optimize SSE2 and AVX2 variants Richard Henderson
2024-02-15 8:14 ` [PATCH v4 06/10] util/bufferiszero: Improve scalar variant Richard Henderson
2024-02-15 8:14 ` [PATCH v4 07/10] util/bufferiszero: Introduce biz_accel_fn typedef Richard Henderson
2024-02-15 8:34 ` Philippe Mathieu-Daudé
2024-02-15 8:14 ` [PATCH v4 08/10] util/bufferiszero: Simplify test_buffer_is_zero_next_accel Richard Henderson
2024-02-15 8:40 ` Philippe Mathieu-Daudé
2024-02-15 8:14 ` [PATCH v4 09/10] util/bufferiszero: Add simd acceleration for aarch64 Richard Henderson
2024-02-15 8:47 ` Alexander Monakov
2024-02-15 17:47 ` Richard Henderson
2024-02-15 18:46 ` Alexander Monakov
2024-02-15 21:10 ` Richard Henderson
2024-02-15 8:14 ` [RFC PATCH v4 10/10] util/bufferiszero: Add sve " Richard Henderson
2024-02-16 9:33 ` Alex Bennée
2024-02-16 11:05 ` Alex Bennée
2024-02-15 8:57 ` [PATCH v4 00/10] Optimize buffer_is_zero Alexander Monakov
2024-02-15 21:16 ` Richard Henderson
2024-02-15 21:36 ` Alexander Monakov
2024-02-15 22:27 ` Richard Henderson
2024-02-15 23:37 ` Alexander Monakov
2024-02-16 8:11 ` Richard Henderson [this message]
2024-02-16 20:20 ` Alexander Monakov
2024-02-16 22:28 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=08ce9292-75a0-4092-a12e-9a12826847b0@linaro.org \
--to=richard.henderson@linaro.org \
--cc=amonakov@ispras.ru \
--cc=mmromanov@ispras.ru \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).