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, 13 May 2009
 13:49:32 -0700
Received: from psmtp.com ([64.18.0.165]) by mail.onstor.com with Microsoft
 SMTPSVC(6.0.3790.3959);	 Wed, 13 May 2009 13:49:32 -0700
Received: from source ([213.58.128.207]) by exprod5mx245.postini.com
 ([64.18.4.13]) with SMTP;	Wed, 13 May 2009 16:49:31 EDT
Received: from localhost.localdomain ([127.0.0.1]:43623 "EHLO
	ftp.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S20025187AbZEMUt3 (ORCPT	<rfc822;andy.sharp@onstor.com>); Wed, 13
 May 2009 21:49:29 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Wed, 13 May 2009 21:49:12
 +0100 (BST)
Received: from mail3.caviumnetworks.com ([12.108.191.235]:20877 "EHLO
	mail3.caviumnetworks.com" rhost-flags-OK-OK-OK-OK)	by ftp.linux-mips.org with
 ESMTP id S20025127AbZEMUtB (ORCPT	<rfc822;linux-mips@linux-mips.org>); Wed,
 13 May 2009 21:49:01 +0100
Received: from exch4.caveonetworks.com (Not Verified[192.168.16.23]) by
 mail3.caviumnetworks.com with MailMarshal (v6,2,2,3503)	id <B4a0b32310003>;
 Wed, 13 May 2009 16:48:49 -0400
Received: from exch4.caveonetworks.com ([192.168.16.23]) by
 exch4.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959);	 Wed, 13 May
 2009 13:48:41 -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, 13 May 2009 13:48:41 -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 n4DKmc0m021354;	Wed, 13
 May 2009 13:48:38 -0700
Received: (from ddaney@localhost)	by dd1.caveonetworks.com
 (8.14.2/8.14.2/Submit) id n4DKmcEm021353;	Wed, 13 May 2009 13:48:38 -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>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Wed, 13 May 2009 13:48:37 -0700
Subject: [PATCH 2/2] MIPS: Don't branch to eret in TLB refill.
Thread-Topic: [PATCH 2/2] MIPS: Don't branch to eret in TLB refill.
Thread-Index: AcnUDFGhfqXQgisOT++GZx2VSeYM9Q==
Message-ID: <1242247717-21324-2-git-send-email-ddaney@caviumnetworks.com>
References: <4A0B31C6.9050804@caviumnetworks.com>
In-Reply-To: <4A0B31C6.9050804@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: 13 May 2009 20:48:41.0109 (UTC)
 FILETIME=[32A43C50:01C9D40C]
x-ems-stamp: mza4bZAoyY4Nq3cBdogLpw==
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-neptune: 0/0/0.00/0
x-pstn-levels: (S:98.11103/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: 22705
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

If the TLB refill handler is too big and needs to be split, there is
no need to branch around the split if the branch target would be an
eret.  Since the eret returns from the handler, control flow never
passes it.  A branch to an eret is equivalent to the eret itself.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---
 arch/mips/mm/tlbex.c |   66 ++++++++++++++++++++++++++++++----------------=
---
 1 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index d99ed78..0a88383 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -664,6 +664,7 @@ static void __cpuinit build_r4000_tlb_refill_handler(vo=
id)
 	struct uasm_reloc *r =3D relocs;
 	u32 *f;
 	unsigned int final_len;
+	int split_on_eret;
=20
 	memset(tlb_handler, 0, sizeof(tlb_handler));
 	memset(labels, 0, sizeof(labels));
@@ -693,6 +694,12 @@ static void __cpuinit build_r4000_tlb_refill_handler(v=
oid)
 	build_tlb_write_entry(&p, &l, &r, tlb_random);
 	uasm_l_leave(&l, p);
 	uasm_i_eret(&p); /* return from trap */
+	/*
+	 * Check to see if the eret was the last instruction before
+	 * the split.  If it was, there will be no need to branch
+	 * around the split, because we are returning.
+	 */
+	split_on_eret =3D (p - tlb_handler =3D=3D MIPS64_REFILL_INSNS);
=20
 #ifdef CONFIG_64BIT
 	build_get_pgd_vmalloc64(&p, &l, &r, K0, K1);
@@ -732,36 +739,43 @@ 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;
-
-		/*
-		 * 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.
-		 */
-		if (uasm_insn_has_bdelay(relocs, split - 1))
-			split--;
-
+		u32 *split;
+		if (split_on_eret) {
+			split =3D tlb_handler + MIPS64_REFILL_INSNS;
+		} 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;
+
+			/*
+			 * 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.
+			 */
+			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 (!split_on_eret) {
+			/* 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


