* [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr
@ 2011-03-10 20:47 Vincent Palatin
2011-03-10 21:14 ` [Qemu-devel] " Alex Williamson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Vincent Palatin @ 2011-03-10 20:47 UTC (permalink / raw)
To: Qemu devel
Cc: Chris Wright, Alex Williamson, Vincent Palatin, Anthony Liguori
When the commit f471a17e9d869df3c6573f7ec02c4725676d6f3a converted the
ram_blocks structure to QLIST, it also removed the conditional check before
switching the current block at the beginning of the list.
In the common use case where ram_blocks has a few blocks with only one
frequently accessed (the main RAM), this has a performance impact as it
performs the useless list operations on each call (which are on a really
hot path).
On my machine emulation (ARM on amd64), this patch reduces the
percentage of CPU time spent in qemu_get_ram_ptr from 6.3% to 2.1% in the
profiling of a full boot.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
exec.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/exec.c b/exec.c
index d611100..81f08b7 100644
--- a/exec.c
+++ b/exec.c
@@ -2957,8 +2957,11 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr - block->offset < block->length) {
- QLIST_REMOVE(block, next);
- QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
+ /* Move this entry to to start of the list. */
+ if (block != QLIST_FIRST(&ram_list.blocks)) {
+ QLIST_REMOVE(block, next);
+ QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
+ }
return block->host + (addr - block->offset);
}
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH] Fix performance regression in qemu_get_ram_ptr
2011-03-10 20:47 [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr Vincent Palatin
@ 2011-03-10 21:14 ` Alex Williamson
2011-03-10 21:52 ` Chris Wright
2011-03-10 23:17 ` Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2011-03-10 21:14 UTC (permalink / raw)
To: Vincent Palatin; +Cc: Chris Wright, Anthony Liguori, Qemu devel
On Thu, 2011-03-10 at 15:47 -0500, Vincent Palatin wrote:
> When the commit f471a17e9d869df3c6573f7ec02c4725676d6f3a converted the
> ram_blocks structure to QLIST, it also removed the conditional check before
> switching the current block at the beginning of the list.
>
> In the common use case where ram_blocks has a few blocks with only one
> frequently accessed (the main RAM), this has a performance impact as it
> performs the useless list operations on each call (which are on a really
> hot path).
>
> On my machine emulation (ARM on amd64), this patch reduces the
> percentage of CPU time spent in qemu_get_ram_ptr from 6.3% to 2.1% in the
> profiling of a full boot.
>
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> ---
> exec.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index d611100..81f08b7 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2957,8 +2957,11 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
>
> QLIST_FOREACH(block, &ram_list.blocks, next) {
> if (addr - block->offset < block->length) {
> - QLIST_REMOVE(block, next);
> - QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + /* Move this entry to to start of the list. */
> + if (block != QLIST_FIRST(&ram_list.blocks)) {
> + QLIST_REMOVE(block, next);
> + QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + }
> return block->host + (addr - block->offset);
> }
> }
Looks good
Acked-by: Alex Williamson <alex.williamson@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH] Fix performance regression in qemu_get_ram_ptr
2011-03-10 20:47 [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr Vincent Palatin
2011-03-10 21:14 ` [Qemu-devel] " Alex Williamson
@ 2011-03-10 21:52 ` Chris Wright
2011-03-10 23:17 ` Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Chris Wright @ 2011-03-10 21:52 UTC (permalink / raw)
To: Vincent Palatin
Cc: Chris Wright, Alex Williamson, Qemu devel, Anthony Liguori
* Vincent Palatin (vpalatin@chromium.org) wrote:
> When the commit f471a17e9d869df3c6573f7ec02c4725676d6f3a converted the
> ram_blocks structure to QLIST, it also removed the conditional check before
> switching the current block at the beginning of the list.
Nice catch.
> In the common use case where ram_blocks has a few blocks with only one
> frequently accessed (the main RAM), this has a performance impact as it
> performs the useless list operations on each call (which are on a really
> hot path).
>
> On my machine emulation (ARM on amd64), this patch reduces the
> percentage of CPU time spent in qemu_get_ram_ptr from 6.3% to 2.1% in the
> profiling of a full boot.
Hopefully this is back on par with before the QLIST switchover.
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Acked-by: Chris Wright <chrisw@redhat.com>
> ---
> exec.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index d611100..81f08b7 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2957,8 +2957,11 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
>
> QLIST_FOREACH(block, &ram_list.blocks, next) {
> if (addr - block->offset < block->length) {
> - QLIST_REMOVE(block, next);
> - QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + /* Move this entry to to start of the list. */
> + if (block != QLIST_FIRST(&ram_list.blocks)) {
> + QLIST_REMOVE(block, next);
> + QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + }
Pretty close to self-documenting code now. Not sure if it's subtle enough
to warrant change to the comment like:
/* Move block to head of list if it's not there already */
thanks,
-chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH] Fix performance regression in qemu_get_ram_ptr
2011-03-10 20:47 [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr Vincent Palatin
2011-03-10 21:14 ` [Qemu-devel] " Alex Williamson
2011-03-10 21:52 ` Chris Wright
@ 2011-03-10 23:17 ` Anthony Liguori
2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2011-03-10 23:17 UTC (permalink / raw)
To: Vincent Palatin; +Cc: Chris Wright, Alex Williamson, Qemu devel
On 03/10/2011 02:47 PM, Vincent Palatin wrote:
> When the commit f471a17e9d869df3c6573f7ec02c4725676d6f3a converted the
> ram_blocks structure to QLIST, it also removed the conditional check before
> switching the current block at the beginning of the list.
>
> In the common use case where ram_blocks has a few blocks with only one
> frequently accessed (the main RAM), this has a performance impact as it
> performs the useless list operations on each call (which are on a really
> hot path).
>
> On my machine emulation (ARM on amd64), this patch reduces the
> percentage of CPU time spent in qemu_get_ram_ptr from 6.3% to 2.1% in the
> profiling of a full boot.
>
> Signed-off-by: Vincent Palatin<vpalatin@chromium.org>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> exec.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index d611100..81f08b7 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2957,8 +2957,11 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
>
> QLIST_FOREACH(block,&ram_list.blocks, next) {
> if (addr - block->offset< block->length) {
> - QLIST_REMOVE(block, next);
> - QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + /* Move this entry to to start of the list. */
> + if (block != QLIST_FIRST(&ram_list.blocks)) {
> + QLIST_REMOVE(block, next);
> + QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
> + }
> return block->host + (addr - block->offset);
> }
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-10 23:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 20:47 [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr Vincent Palatin
2011-03-10 21:14 ` [Qemu-devel] " Alex Williamson
2011-03-10 21:52 ` Chris Wright
2011-03-10 23:17 ` Anthony Liguori
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).