Received: from [140.186.70.92] (port=52362 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PO90k-0000yZ-Pt for qemu-devel@nongnu.org; Thu, 02 Dec 2010 08:18:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PO8yD-00079c-SD for qemu-devel@nongnu.org; Thu, 02 Dec 2010 08:15:45 -0500 Received: from smtp.ispras.ru ([83.149.198.201]:50809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PO8yD-00074L-GG for qemu-devel@nongnu.org; Thu, 02 Dec 2010 08:13:09 -0500 Received: from ispserv.ispras.ru (ispserv.ispras.ru [83.149.198.72]) by smtp.ispras.ru (Postfix) with ESMTP id BE7705D4102 for ; Thu, 2 Dec 2010 16:07:37 +0300 (MSK) Received: from spartak.intra.ispras.ru (winnie.ispras.ru [83.149.198.236]) by ispserv.ispras.ru (Postfix) with ESMTP id 0E4293FC48 for ; Thu, 2 Dec 2010 16:12:46 +0300 (MSK) Date: Thu, 2 Dec 2010 16:12:46 +0300 (MSK) From: Kirill Batuzov Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1028111204-1291295566=:24917" Subject: [Qemu-devel] [PATCH] Speedup 'tb_find_slow' by using the same heuristic as during memory page lookup List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1028111204-1291295566=:24917 Content-Type: TEXT/PLAIN; charset=US-ASCII Move the last found TB to the head of the list so it will be found more quickly next time it will be looked for. Signed-off-by: Kirill Batuzov Signed-off-by: Pavel Yushchenko --- This patch appeared during investigation of performance issues with S5PC110 emulation for Samsung. It increses OS startup speed significantly. Changes from previous version, submitted with RFT tag: - 'likely' was added to if condition, - comment was added. diff --git a/cpu-exec.c b/cpu-exec.c index dbdfdcc..39e5eea 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -167,6 +167,12 @@ static TranslationBlock *tb_find_slow(target_ulong pc, tb = tb_gen_code(env, pc, cs_base, flags, 0); found: + /* Move the last found TB to the head of the list */ + if (likely(*ptb1)) { + *ptb1 = tb->phys_hash_next; + tb->phys_hash_next = tb_phys_hash[h]; + tb_phys_hash[h] = tb; + } /* we add the TB in the virtual pc hash table */ env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)] = tb; return tb; --8323329-1028111204-1291295566=:24917 Content-Type: TEXT/x-diff; name=tb_find_slow-locality-heuristic.patch Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=tb_find_slow-locality-heuristic.patch ZGlmZiAtLWdpdCBhL2NwdS1leGVjLmMgYi9jcHUtZXhlYy5jDQppbmRleCBk YmRmZGNjLi4zOWU1ZWVhIDEwMDY0NA0KLS0tIGEvY3B1LWV4ZWMuYw0KKysr IGIvY3B1LWV4ZWMuYw0KQEAgLTE2Nyw2ICsxNjcsMTIgQEAgc3RhdGljIFRy YW5zbGF0aW9uQmxvY2sgKnRiX2ZpbmRfc2xvdyh0YXJnZXRfdWxvbmcgcGMs DQogICAgIHRiID0gdGJfZ2VuX2NvZGUoZW52LCBwYywgY3NfYmFzZSwgZmxh Z3MsIDApOw0KIA0KICBmb3VuZDoNCisgICAgLyogTW92ZSB0aGUgbGFzdCBm b3VuZCBUQiB0byB0aGUgaGVhZCBvZiB0aGUgbGlzdCAqLw0KKyAgICBpZiAo bGlrZWx5KCpwdGIxKSkgew0KKyAgICAgICAgKnB0YjEgPSB0Yi0+cGh5c19o YXNoX25leHQ7DQorICAgICAgICB0Yi0+cGh5c19oYXNoX25leHQgPSB0Yl9w aHlzX2hhc2hbaF07DQorICAgICAgICB0Yl9waHlzX2hhc2hbaF0gPSB0YjsN CisgICAgfQ0KICAgICAvKiB3ZSBhZGQgdGhlIFRCIGluIHRoZSB2aXJ0dWFs IHBjIGhhc2ggdGFibGUgKi8NCiAgICAgZW52LT50Yl9qbXBfY2FjaGVbdGJf am1wX2NhY2hlX2hhc2hfZnVuYyhwYyldID0gdGI7DQogICAgIHJldHVybiB0 YjsNCg== --8323329-1028111204-1291295566=:24917--