From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, quintela@redhat.com, eblake@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing
Date: Wed, 10 Jan 2018 15:25:14 +0100 [thread overview]
Message-ID: <20180110142515.13242-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20180110142515.13242-1-pbonzini@redhat.com>
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Add some comments and rename the "end" variable so I can understand the
various nested loops. Add some tracing so I can see what they're doing.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20180105170138.23357-2-dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
exec.c | 29 ++++++++++++++++++++++-------
trace-events | 4 ++++
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/exec.c b/exec.c
index ff31e7165f..829f9d8d1a 100644
--- a/exec.c
+++ b/exec.c
@@ -1661,7 +1661,10 @@ static void *file_ram_alloc(RAMBlock *block,
}
#endif
-/* Called with the ramlist lock held. */
+/* Allocate space within the ram_addr_t space that governs the
+ * dirty bitmaps.
+ * Called with the ramlist lock held.
+ */
static ram_addr_t find_ram_offset(ram_addr_t size)
{
RAMBlock *block, *next_block;
@@ -1674,19 +1677,29 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
}
RAMBLOCK_FOREACH(block) {
- ram_addr_t end, next = RAM_ADDR_MAX;
+ ram_addr_t candidate, next = RAM_ADDR_MAX;
- end = block->offset + block->max_length;
+ candidate = block->offset + block->max_length;
+ /* Search for the closest following block
+ * and find the gap.
+ */
RAMBLOCK_FOREACH(next_block) {
- if (next_block->offset >= end) {
+ if (next_block->offset >= candidate) {
next = MIN(next, next_block->offset);
}
}
- if (next - end >= size && next - end < mingap) {
- offset = end;
- mingap = next - end;
+
+ /* If it fits remember our place and remember the size
+ * of gap, but keep going so that we might find a smaller
+ * gap to fill so avoiding fragmentation.
+ */
+ if (next - candidate >= size && next - candidate < mingap) {
+ offset = candidate;
+ mingap = next - candidate;
}
+
+ trace_find_ram_offset_loop(size, candidate, offset, next, mingap);
}
if (offset == RAM_ADDR_MAX) {
@@ -1695,6 +1708,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
abort();
}
+ trace_find_ram_offset(size, offset);
+
return offset;
}
diff --git a/trace-events b/trace-events
index 3695959d0a..a676b02a20 100644
--- a/trace-events
+++ b/trace-events
@@ -55,6 +55,10 @@ dma_complete(void *dbs, int ret, void *cb) "dbs=%p ret=%d cb=%p"
dma_blk_cb(void *dbs, int ret) "dbs=%p ret=%d"
dma_map_wait(void *dbs) "dbs=%p"
+# # exec.c
+find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%"PRIx64 " @ 0x%"PRIx64
+find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_t next, uint64_t mingap) "trying size: 0x%"PRIx64 " @ 0x%"PRIx64 ," offset: 0x%"PRIx64" next: 0x%"PRIx64 " mingap: 0x%"PRIx64
+
# memory.c
memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u"
memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u"
--
2.14.3
next prev parent reply other threads:[~2018-01-10 14:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-10 14:25 [Qemu-devel] [PATCH v2 0/2] find_ram_offset cleanups and alignment Paolo Bonzini
2018-01-10 14:25 ` Paolo Bonzini [this message]
2018-01-10 14:25 ` [Qemu-devel] [PATCH 2/2] find_ram_offset: Align ram_addr_t allocation on long boundaries Paolo Bonzini
2018-01-10 14:31 ` [Qemu-devel] [PATCH v2 0/2] find_ram_offset cleanups and alignment no-reply
2018-01-10 14:32 ` no-reply
2018-01-10 14:37 ` Dr. David Alan Gilbert
2018-01-10 15:04 ` Dr. David Alan Gilbert
2018-01-10 15:08 ` Eric Blake
2018-01-10 14:44 ` no-reply
-- strict thread matches above, loose matches on Subject: below --
2018-01-05 17:01 [Qemu-devel] [PATCH " Dr. David Alan Gilbert (git)
2018-01-05 17:01 ` [Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing Dr. David Alan Gilbert (git)
2018-01-05 17:20 ` Eric Blake
2018-01-08 22:08 ` Juan Quintela
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=20180110142515.13242-2-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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).