Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LesmN-0004XE-Ln for qemu-devel@nongnu.org; Wed, 04 Mar 2009 10:13:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LesmM-0004W5-KC for qemu-devel@nongnu.org; Wed, 04 Mar 2009 10:13:03 -0500 Received: from [199.232.76.173] (port=60050 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LesmM-0004Vz-FN for qemu-devel@nongnu.org; Wed, 04 Mar 2009 10:13:02 -0500 Received: from vsmtp02.dti.ne.jp ([202.216.231.137]:39228) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LesmL-0003OG-Io for qemu-devel@nongnu.org; Wed, 04 Mar 2009 10:13:02 -0500 Received: from [192.168.1.22] (PPPa1209.e11.eacc.dti.ne.jp [124.255.90.198]) by vsmtp02.dti.ne.jp (3.11v) with ESMTP AUTH id n24FCw9V005285 for ; Thu, 5 Mar 2009 00:12:58 +0900 (JST) Message-ID: <49AE9A7A.7060502@juno.dti.ne.jp> Date: Thu, 05 Mar 2009 00:12:58 +0900 From: Shin-ichiro KAWASAKI MIME-Version: 1.0 Subject: Re: [Qemu-devel] sh : performance problem References: <49A6C317.1080202@juno.dti.ne.jp> <1236038327.4975.16.camel@coalu.atr> <49AD50E2.7000401@juno.dti.ne.jp> <1236121899.4005.17.camel@coalu.atr> In-Reply-To: <1236121899.4005.17.camel@coalu.atr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Lionel Landwerlin wrote: > Le mercredi 04 mars 2009 =C3=A0 00:46 +0900, Shin-ichiro KAWASAKI a =C3= =A9crit : >> Lionel Landwerlin wrote: >>> Shin-ichiro, >>> >>> Sorry, but I cannot apply your patch cleanly on the last qemu-svn. >>> >>> Instead, I would like to try another approach. The patch you proposed= to >>> find (or not) a valid TLB entry has a complexity of O(log2(n)) (or >>> something like that if I remember) instead here is a patch with a >>> complexity of O(1). >> Good work. I evaluated your patch on my environment, measuring >> compile time for empty main() with gcc. >> >> sh4 : 5.8 [seconds] O(n) utlb search. >> sh4 : 4.6 [seconds] O(log2(n)) utlb search. >> sh4 : 4.1 [seconds] O(1) utlb search by Lionel >> arm : 0.8 [seconds] (-M versatilepb + Debian ARM) >> >> Your patch has a nice score! >> >> Now I've done the work to increase number of utlb entries from 64 to 2= 56, >> and found that the score get arround 2.4 seconds. >> I'm trying to increase it to 4096. Your O(1) search will be more impo= rtant >> as the entry number increase. >=20 > We should setup a git repository to improve that or at least work on th= e > same basis. >=20 > Do you have a lot of patch on top of the last svn ? I personally manages my staging repository corresponds to 'qemu-sh'. git://github.com/kawasaki/qemu-sh.git http://github.com/kawasaki/qemu-sh/tree/master Patches in it can be applied to current qemu subversion trunk. I put your O(1) patch and my utlb entry increasing patch also. Will it work as the basis? I attach the utlb entry increasing patch to this mail for reference. It should be applied with other patches in my staging repository, or patch command will fail. It increases the number of utlb entry from 64 to 256. URC and URB values in MMUCR can take the number from 0 to 255. Here's the benchmark value. sh4 : 5.8 [seconds] O(n) utlb search. sh4 : 4.6 [seconds] O(log2(n)) utlb search. sh4 : 4.1 [seconds] O(1) utlb search by Lionel sh4 : 2.1 [seconds] O(1) utlb search, and 256 utlb enries <=3D=20 arm : 0.8 [seconds] (-M versatilepb + Debian ARM) Getting better :) but still behind arm. Regards, Shin-ichiro KAWASAKI Index: trunk/target-sh4/cpu.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/target-sh4/cpu.h (revision 6676) +++ trunk/target-sh4/cpu.h (working copy) @@ -88,7 +88,8 @@ uint8_t tc; /* timing control */ } tlb_t; =20 -#define UTLB_SIZE 64 +#define UTLB_BITS 8 /* real hard : 6 */ +#define UTLB_SIZE (1 << UTLB_BITS) #define ITLB_SIZE 4 =20 #define NB_MMU_MODES 2 @@ -228,14 +229,18 @@ #define MMUCR 0x1F000010 #define MMUCR_AT (1<<0) #define MMUCR_SV (1<<8) -#define MMUCR_URC_BITS (6) #define MMUCR_URC_OFFSET (10) -#define MMUCR_URC_SIZE (1 << MMUCR_URC_BITS) -#define MMUCR_URC_MASK (((MMUCR_URC_SIZE) - 1) << MMUCR_URC_OFFSET) +#define MMUCR_URC_MASK ((UTLB_SIZE - 1) << MMUCR_URC_OFFSET) static inline int cpu_mmucr_urc (uint32_t mmucr) { return ((mmucr & MMUCR_URC_MASK) >> MMUCR_URC_OFFSET); } +#define MMUCR_URB_OFFSET (18) +#define MMUCR_URB_MASK ((UTLB_SIZE - 1) << MMUCR_URB_OFFSET) +static inline int cpu_mmucr_urb (uint32_t mmucr) +{ + return ((mmucr & MMUCR_URB_MASK) >> MMUCR_URB_OFFSET); +} =20 /* PTEH : Page Translation Entry High register */ #define PTEH_ASID_BITS (8) Index: trunk/target-sh4/helper.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/target-sh4/helper.c (revision 6676) +++ trunk/target-sh4/helper.c (work copy) @@ -346,12 +346,12 @@ uint8_t urb, urc; =20 /* Increment URC */ - urb =3D ((env->mmucr) >> 18) & 0x3f; - urc =3D ((env->mmucr) >> 10) & 0x3f; + urb =3D cpu_mmucr_urb(env->mmucr); + urc =3D cpu_mmucr_urc(env->mmucr); urc++; if ((urb > 0 && urc > urb) || urc > (UTLB_SIZE - 1)) - urc =3D 0; - env->mmucr =3D (env->mmucr & 0xffff03ff) | (urc << 10); + urc =3D 0; + env->mmucr =3D (env->mmucr & ~MMUCR_URC_MASK) | (urc << MMUCR_URC_OF= FSET); } =20 /* Find itlb entry - update itlb from utlb if necessary and asked for