Received: from eggs.gnu.org ([2001:4830:134:3::10]:42599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a99of-0005D0-Sq for qemu-devel@nongnu.org; Wed, 16 Dec 2015 06:00:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a99ob-0003ak-Ki for qemu-devel@nongnu.org; Wed, 16 Dec 2015 06:00:17 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:35371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a99ob-0003aY-CY for qemu-devel@nongnu.org; Wed, 16 Dec 2015 06:00:13 -0500 Received: by mail-wm0-x235.google.com with SMTP id l126so33070569wml.0 for ; Wed, 16 Dec 2015 03:00:13 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 16 Dec 2015 11:59:58 +0100 Message-Id: <1450263601-2828-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1450263601-2828-1-git-send-email-pbonzini@redhat.com> References: <1450263601-2828-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 6/8] memory: extract first iteration of address_space_read and address_space_write List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: v.maffione@gmail.com We want to inline the case where there is only one iteration, because then the compiler can also inline the memcpy. As a start, extract everything after the first address_space_translate call. Signed-off-by: Paolo Bonzini --- exec.c | 87 ++++++++++++++++++++++++++++++++++++++------------- include/exec/memory.h | 6 ++++ 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/exec.c b/exec.c index 44b04ba..12313bd 100644 --- a/exec.c +++ b/exec.c @@ -2495,22 +2495,19 @@ static bool prepare_mmio_access(MemoryRegion *mr) return release_lock; } -MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, - const uint8_t *buf, int len) +/* Called within RCU critical section. */ +static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const uint8_t *buf, + int len, hwaddr addr1, + hwaddr l, MemoryRegion *mr) { - hwaddr l; uint8_t *ptr; uint64_t val; - hwaddr addr1; - MemoryRegion *mr; MemTxResult result = MEMTX_OK; bool release_lock = false; - rcu_read_lock(); - while (len > 0) { - l = len; - mr = address_space_translate(as, addr, &addr1, &l, true); - + for (;;) { if (!memory_access_is_direct(mr, true)) { release_lock |= prepare_mmio_access(mr); l = memory_access_size(mr, l, addr1); @@ -2560,28 +2557,50 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, len -= l; buf += l; addr += l; + + if (!len) { + break; + } + + l = len; + mr = address_space_translate(as, addr, &addr1, &l, true); } - rcu_read_unlock(); return result; } -MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, - uint8_t *buf, int len) +MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, + const uint8_t *buf, int len) { hwaddr l; - uint8_t *ptr; - uint64_t val; hwaddr addr1; MemoryRegion *mr; MemTxResult result = MEMTX_OK; + + if (len > 0) { + rcu_read_lock(); + l = len; + mr = address_space_translate(as, addr, &addr1, &l, true); + result = address_space_write_continue(as, addr, attrs, buf, len, + addr1, l, mr); + rcu_read_unlock(); + } + + return result; +} + +/* Called within RCU critical section. */ +MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, + int len, hwaddr addr1, hwaddr l, + MemoryRegion *mr) +{ + uint8_t *ptr; + uint64_t val; + MemTxResult result = MEMTX_OK; bool release_lock = false; - rcu_read_lock(); - while (len > 0) { - l = len; - mr = address_space_translate(as, addr, &addr1, &l, false); - + for (;;) { if (!memory_access_is_direct(mr, false)) { /* I/O case */ release_lock |= prepare_mmio_access(mr); @@ -2628,8 +2647,34 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, len -= l; buf += l; addr += l; + + if (!len) { + break; + } + + l = len; + mr = address_space_translate(as, addr, &addr1, &l, false); + } + + return result; +} + +MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, + uint8_t *buf, int len) +{ + hwaddr l; + hwaddr addr1; + MemoryRegion *mr; + MemTxResult result = MEMTX_OK; + + if (len > 0) { + rcu_read_lock(); + l = len; + mr = address_space_translate(as, addr, &addr1, &l, false); + result = address_space_read_continue(as, addr, attrs, buf, len, + addr1, l, mr); + rcu_read_unlock(); } - rcu_read_unlock(); return result; } diff --git a/include/exec/memory.h b/include/exec/memory.h index 24b7cba..3680d6a 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1366,6 +1366,12 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, int is_write, hwaddr access_len); +/* Internal functions, part of the implementation of address_space_read. */ +MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, + int len, hwaddr addr1, hwaddr l, + MemoryRegion *mr); + #endif #endif -- 2.5.0