Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Wed, 20 May 2009
 11:42:44 -0700
Received: from psmtp.com ([64.18.0.79]) by mail.onstor.com with Microsoft
 SMTPSVC(6.0.3790.3959);	 Wed, 20 May 2009 11:41:41 -0700
Received: from source ([213.58.128.207]) by exprod5mx220.postini.com
 ([64.18.4.10]) with SMTP;	Wed, 20 May 2009 11:41:39 PDT
Received: from localhost.localdomain ([127.0.0.1]:38237 "EHLO
	ftp.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S20025106AbZETSlh (ORCPT	<rfc822;andy.sharp@onstor.com>); Wed, 20
 May 2009 19:41:37 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Wed, 20 May 2009 19:41:20
 +0100 (BST)
Received: from mail3.caviumnetworks.com ([12.108.191.235]:22142 "EHLO
	mail3.caviumnetworks.com" rhost-flags-OK-OK-OK-OK)	by ftp.linux-mips.org with
 ESMTP id S20025103AbZETSlN (ORCPT	<rfc822;linux-mips@linux-mips.org>); Wed,
 20 May 2009 19:41:13 +0100
Received: from exch4.caveonetworks.com (Not Verified[192.168.16.23]) by
 mail3.caviumnetworks.com with MailMarshal (v6,2,2,3503)	id <B4a144ebd0000>;
 Wed, 20 May 2009 14:41:01 -0400
Received: from exch4.caveonetworks.com ([192.168.16.23]) by
 exch4.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959);	 Wed, 20 May
 2009 11:41:04 -0700
Received: from dd1.caveonetworks.com ([64.169.86.201]) by
 exch4.caveonetworks.com over TLS secured channel with Microsoft
 SMTPSVC(6.0.3790.3959);	 Wed, 20 May 2009 11:41:04 -0700
Received: from dd1.caveonetworks.com (localhost.localdomain [127.0.0.1])	by
 dd1.caveonetworks.com (8.14.2/8.14.2) with ESMTP id n4KIf1pj006818;	Wed, 20
 May 2009 11:41:02 -0700
Received: (from ddaney@localhost)	by dd1.caveonetworks.com
 (8.14.2/8.14.2/Submit) id n4KIf1EY006817;	Wed, 20 May 2009 11:41:01 -0700
From: David Daney <ddaney@caviumnetworks.com>
To: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	"ralf@linux-mips.org" <ralf@linux-mips.org>
CC: David Daney <ddaney@caviumnetworks.com>, "Maciej W. Rozycki"
	<macro@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Wed, 20 May 2009 11:40:59 -0700
Subject: [PATCH 2/2] MIPS: Fold the TLB refill at the vmalloc path if
 possible.
Thread-Topic: [PATCH 2/2] MIPS: Fold the TLB refill at the vmalloc path if
 possible.
Thread-Index: AcnZesOvtSEwyv0STJOVeZurx1j44w==
Message-ID: <1242844859-6788-2-git-send-email-ddaney@caviumnetworks.com>
References: <4A144DFF.90602@caviumnetworks.com>
In-Reply-To: <4A144DFF.90602@caviumnetworks.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 20 May 2009 18:41:04.0395 (UTC)
 FILETIME=[87C6A5B0:01C9D97A]
x-ems-stamp: xscxrdE61aQPGuWf9PnRIA==
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:88.66966/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-list: linux-mips
x-archive-position: 22845
x-ecartis-version: Ecartis v1.0.0
x-original-sender: ddaney@caviumnetworks.com
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Try to fold the 64-bit TLB refill handler opportunistically at the
beginning of the vmalloc path so as to avoid splitting execution flow in
half and wasting cycles for a branch required at that point then.  Resort
to doing the split if either of the newly created parts would not fit into
its designated slot.

Original-patch-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---
 arch/mips/mm/tlbex.c |   73 +++++++++++++++++++++++++++++++++-------------=
---
 1 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index cbc09de..62fbd0d 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -6,7 +6,7 @@
  * Synthesize TLB refill handlers at runtime.
  *
  * Copyright (C) 2004, 2005, 2006, 2008  Thiemo Seufer
- * Copyright (C) 2005, 2007  Maciej W. Rozycki
+ * Copyright (C) 2005, 2007, 2008, 2009  Maciej W. Rozycki
  * Copyright (C) 2006  Ralf Baechle (ralf@linux-mips.org)
  *
  * ... and the days got worse and worse and now you see
@@ -19,6 +19,7 @@
  * (Condolences to Napoleon XIV)
  */
=20
+#include <linux/bug.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/string.h>
@@ -732,36 +733,60 @@ static void __cpuinit build_r4000_tlb_refill_handler(=
void)
 		uasm_copy_handler(relocs, labels, tlb_handler, p, f);
 		final_len =3D p - tlb_handler;
 	} else {
-		/*
-		 * Split two instructions before the end.  One for the
-		 * branch and one for the instruction in the delay
-		 * slot.
-		 */
-		u32 *split =3D tlb_handler + MIPS64_REFILL_INSNS - 2;
+#ifdef MODULE_START
+		const enum label_id ls =3D label_module_alloc;
+#else
+		const enum label_id ls =3D label_vmalloc;
+#endif
+		u32 *split;
+		int ov =3D 0;
+		int i;
+
+		for (i =3D 0; i < ARRAY_SIZE(labels) && labels[i].lab !=3D ls; i++)
+			;
+		BUG_ON(i =3D=3D ARRAY_SIZE(labels));
+		split =3D labels[i].addr;
=20
 		/*
-		 * Find the split point.  If the branch would fall in
-		 * a delay slot, we must back up an additional
-		 * instruction so that it is no longer in a delay
-		 * slot.
+		 * See if we have overflown one way or the other.
 		 */
-		if (uasm_insn_has_bdelay(relocs, split - 1))
-			split--;
-
+		if (split > tlb_handler + MIPS64_REFILL_INSNS ||
+		    split < p - MIPS64_REFILL_INSNS)
+			ov =3D 1;
+
+		if (ov) {
+			/*
+			 * Split two instructions before the end.  One
+			 * for the branch and one for the instruction
+			 * in the delay slot.
+			 */
+			split =3D tlb_handler + MIPS64_REFILL_INSNS - 2;
+
+			/*
+			 * If the branch would fall in a delay slot,
+			 * we must back up an additional instruction
+			 * so that it is no longer in a delay slot.
+			 */
+			if (uasm_insn_has_bdelay(relocs, split - 1))
+				split--;
+		}
 		/* Copy first part of the handler. */
 		uasm_copy_handler(relocs, labels, tlb_handler, split, f);
 		f +=3D split - tlb_handler;
=20
-		/* Insert branch. */
-		uasm_l_split(&l, final_handler);
-		uasm_il_b(&f, &r, label_split);
-		if (uasm_insn_has_bdelay(relocs, split))
-			uasm_i_nop(&f);
-		else {
-			uasm_copy_handler(relocs, labels, split, split + 1, f);
-			uasm_move_labels(labels, f, f + 1, -1);
-			f++;
-			split++;
+		if (ov) {
+			/* Insert branch. */
+			uasm_l_split(&l, final_handler);
+			uasm_il_b(&f, &r, label_split);
+			if (uasm_insn_has_bdelay(relocs, split))
+				uasm_i_nop(&f);
+			else {
+				uasm_copy_handler(relocs, labels,
+						  split, split + 1, f);
+				uasm_move_labels(labels, f, f + 1, -1);
+				f++;
+				split++;
+			}
 		}
=20
 		/* Copy the rest of the handler. */
--=20
1.6.0.6


