From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:39719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RxEgJ-0002zJ-Lk for qemu-devel@nongnu.org; Tue, 14 Feb 2012 04:28:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RxEgB-0003WU-T7 for qemu-devel@nongnu.org; Tue, 14 Feb 2012 04:28:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40441) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RxEgB-0003W0-MJ for qemu-devel@nongnu.org; Tue, 14 Feb 2012 04:28:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1E9S6h9002952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Feb 2012 04:28:07 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1E9S2b3013201 for ; Tue, 14 Feb 2012 04:28:06 -0500 From: Avi Kivity Date: Tue, 14 Feb 2012 11:27:47 +0200 Message-Id: <1329211670-11548-18-git-send-email-avi@redhat.com> In-Reply-To: <1329211670-11548-1-git-send-email-avi@redhat.com> References: <1329211670-11548-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 17/20] memory: switch phys_page_set() to a recursive implementation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Setting multiple pages at once requires backtracking to previous nodes; easiest to achieve via recursion. Signed-off-by: Avi Kivity --- exec.c | 67 +++++++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 41 insertions(+), 26 deletions(-) diff --git a/exec.c b/exec.c index 26e70c3..f4cd867 100644 --- a/exec.c +++ b/exec.c @@ -404,24 +404,30 @@ static inline PageDesc *page_find(tb_page_addr_t index) #if !defined(CONFIG_USER_ONLY) -static PhysPageEntry *phys_map_node_alloc(uint16_t *ptr) +static void phys_map_node_reserve(unsigned nodes) { - unsigned i; - uint16_t ret; - - /* Assign early to avoid the pointer being invalidated by g_renew() */ - *ptr = ret = phys_map_nodes_nb++; - assert(ret != PHYS_MAP_NODE_NIL); - if (ret == phys_map_nodes_nb_alloc) { + if (phys_map_nodes_nb + nodes > phys_map_nodes_nb_alloc) { typedef PhysPageEntry Node[L2_SIZE]; phys_map_nodes_nb_alloc = MAX(phys_map_nodes_nb_alloc * 2, 16); + phys_map_nodes_nb_alloc = MAX(phys_map_nodes_nb_alloc, + phys_map_nodes_nb + nodes); phys_map_nodes = g_renew(Node, phys_map_nodes, phys_map_nodes_nb_alloc); } +} + +static uint16_t phys_map_node_alloc(void) +{ + unsigned i; + uint16_t ret; + + ret = phys_map_nodes_nb++; + assert(ret != PHYS_MAP_NODE_NIL); + assert(ret != phys_map_nodes_nb_alloc); for (i = 0; i < L2_SIZE; ++i) { phys_map_nodes[ret][i].u.node = PHYS_MAP_NODE_NIL; } - return phys_map_nodes[ret]; + return ret; } static void phys_map_nodes_reset(void) @@ -429,29 +435,38 @@ static void phys_map_nodes_reset(void) phys_map_nodes_nb = 0; } -static void phys_page_set(target_phys_addr_t index, uint16_t leaf) -{ - PhysPageEntry *lp, *p; - int i, j; - lp = &phys_map; +static void phys_page_set_level(PhysPageEntry *lp, target_phys_addr_t index, + uint16_t leaf, int level) +{ + PhysPageEntry *p; + int i; - /* Level 1..N. */ - for (i = P_L2_LEVELS - 1; i >= 0; i--) { - if (lp->u.node == PHYS_MAP_NODE_NIL) { - p = phys_map_node_alloc(&lp->u.node); - if (i == 0) { - for (j = 0; j < L2_SIZE; j++) { - p[j].u.leaf = phys_section_unassigned; - } + if (lp->u.node == PHYS_MAP_NODE_NIL) { + lp->u.node = phys_map_node_alloc(); + p = phys_map_nodes[lp->u.node]; + if (level == 0) { + for (i = 0; i < L2_SIZE; i++) { + p[i].u.leaf = phys_section_unassigned; } - } else { - p = phys_map_nodes[lp->u.node]; } - lp = &p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)]; + } else { + p = phys_map_nodes[lp->u.node]; } + lp = &p[(index >> (level * L2_BITS)) & (L2_SIZE - 1)]; + + if (level == 0) { + lp->u.leaf = leaf; + } else { + phys_page_set_level(lp, index, leaf, level - 1); + } +} + +static void phys_page_set(target_phys_addr_t index, uint16_t leaf) +{ + phys_map_node_reserve(P_L2_LEVELS); - lp->u.leaf = leaf; + phys_page_set_level(&phys_map, index, leaf, P_L2_LEVELS - 1); } static MemoryRegionSection phys_page_find(target_phys_addr_t index) -- 1.7.9