From: ralf@uni-koblenz.de
To: Vladimir Roganov <roganov@niisi.msk.ru>,
linux-mips@fnet.fr, linux@cthulhu.engr.sgi.com,
linux-mips@vger.rutgers.edu
Subject: Re: get_mmu_context()
Date: Sat, 17 Oct 1998 00:44:08 +0200 [thread overview]
Message-ID: <19981017004408.E3370@uni-koblenz.de> (raw)
In-Reply-To: <3625D799.7D923FA9@niisi.msk.ru>; from Vladimir Roganov on Thu, Oct 15, 1998 at 03:08:09PM +0400
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
Ok, here is the first working and tested version of my runtime patched
get_mmu_context thing. While writing the code I noticed that the code
patching stuff is actually already a part of what I was intending to implement
since long time like for example getting rid of function pointers and can
be used to optimize many more things throughout the kernel. So while some
parts already look somewhat generic I'd like to make them really generic.
The thing is probably going to look somewhat similar to the Sparc btfixup
code which I'm going to read now.
Ralf
[-- Attachment #2: asid-patch --]
[-- Type: text/plain, Size: 10440 bytes --]
Index: linux/arch/mips/mm/andes.c
diff -u linux/arch/mips/mm/andes.c:1.5 linux/arch/mips/mm/andes.c:1.6
--- linux/arch/mips/mm/andes.c:1.5 Fri May 1 08:33:13 1998
+++ linux/arch/mips/mm/andes.c Fri Oct 16 21:22:42 1998
@@ -1,9 +1,8 @@
-/*
+/* $Id: andes.c,v 1.6 1998/10/16 19:22:42 ralf Exp $
+ *
* andes.c: MMU and cache operations for the R10000 (ANDES).
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
- *
- * $Id: andes.c,v 1.5 1998/05/01 06:33:13 ralf Exp $
*/
#include <linux/init.h>
#include <linux/kernel.h>
@@ -13,6 +12,7 @@
#include <asm/pgtable.h>
#include <asm/system.h>
#include <asm/sgialib.h>
+#include <asm/mmu_context.h>
extern unsigned long mips_tlb_entries;
@@ -104,6 +104,7 @@
flush_tlb_mm = andes_flush_tlb_mm;
flush_tlb_range = andes_flush_tlb_range;
flush_tlb_page = andes_flush_tlb_page;
+ andes_asid_setup();
add_wired_entry = andes_add_wired_entry;
Index: linux/arch/mips/mm/fault.c
diff -u linux/arch/mips/mm/fault.c:1.10 linux/arch/mips/mm/fault.c:1.11
--- linux/arch/mips/mm/fault.c:1.10 Thu Sep 17 00:50:44 1998
+++ linux/arch/mips/mm/fault.c Fri Oct 16 21:22:42 1998
@@ -1,4 +1,4 @@
-/* $Id: fault.c,v 1.10 1998/09/16 22:50:44 ralf Exp $
+/* $Id: fault.c,v 1.11 1998/10/16 19:22:42 ralf Exp $
*
* arch/mips/mm/fault.c
*
@@ -26,7 +26,7 @@
extern void die(char *, struct pt_regs *, unsigned long write);
-unsigned long asid_cache = ASID_FIRST_VERSION;
+unsigned long asid_cache;
/*
* Macro for exception fixup code to access integer registers.
Index: linux/arch/mips/mm/init.c
diff -u linux/arch/mips/mm/init.c:1.12 linux/arch/mips/mm/init.c:1.13
--- linux/arch/mips/mm/init.c:1.12 Thu Sep 17 00:50:44 1998
+++ linux/arch/mips/mm/init.c Fri Oct 16 21:22:42 1998
@@ -1,4 +1,4 @@
-/* $Id: init.c,v 1.12 1998/09/16 22:50:44 ralf Exp $
+/* $Id: init.c,v 1.13 1998/10/16 19:22:42 ralf Exp $
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
@@ -33,6 +33,7 @@
#ifdef CONFIG_SGI
#include <asm/sgialib.h>
#endif
+#include <asm/mmu_context.h>
/*
* Define this to effectivly disable the userpage colouring shit.
@@ -463,4 +464,36 @@
val->totalram <<= PAGE_SHIFT;
val->sharedram <<= PAGE_SHIFT;
return;
+}
+
+/* Fixup an immediate instruction */
+__initfunc(static void __i_insn_fixup(unsigned int **start, unsigned int **stop,
+ unsigned int i_const))
+{
+ unsigned int **p, *ip;
+
+ for (p = start;p < stop; p++) {
+ ip = *p;
+ *ip = (*ip & 0xffff0000) | i_const;
+ }
+}
+
+#define i_insn_fixup(section, const) \
+do { \
+ extern unsigned int *__start_ ## section; \
+ extern unsigned int *__stop_ ## section; \
+ __i_insn_fixup(&__start_ ## section, &__stop_ ## section, const); \
+} while(0)
+
+/* Caller is assumed to flush the caches before the first context switch. */
+__initfunc(void __asid_setup(unsigned int inc, unsigned int mask,
+ unsigned int version_mask,
+ unsigned int first_version))
+{
+ i_insn_fixup(__asid_inc, inc);
+ i_insn_fixup(__asid_mask, mask);
+ i_insn_fixup(__asid_version_mask, version_mask);
+ i_insn_fixup(__asid_first_version, first_version);
+
+ asid_cache = first_version;
}
Index: linux/arch/mips/mm/r2300.c
diff -u linux/arch/mips/mm/r2300.c:1.6 linux/arch/mips/mm/r2300.c:1.7
--- linux/arch/mips/mm/r2300.c:1.6 Tue Aug 18 22:45:08 1998
+++ linux/arch/mips/mm/r2300.c Fri Oct 16 21:22:43 1998
@@ -1,9 +1,8 @@
-/*
+/* $Id: r2300.c,v 1.7 1998/10/16 19:22:43 ralf Exp $
+ *
* r2300.c: R2000 and R3000 specific mmu/cache code.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
- *
- * $Id: r2300.c,v 1.6 1998/08/18 20:45:08 ralf Exp $
*/
#include <linux/init.h>
#include <linux/kernel.h>
@@ -14,6 +13,7 @@
#include <asm/pgtable.h>
#include <asm/system.h>
#include <asm/sgialib.h>
+#include <asm/mmu_context.h>
extern unsigned long mips_tlb_entries;
@@ -274,6 +274,7 @@
flush_tlb_mm = r2300_flush_tlb_mm;
flush_tlb_range = r2300_flush_tlb_range;
flush_tlb_page = r2300_flush_tlb_page;
+ r3000_asid_setup();
load_pgd = r2300_load_pgd;
pgd_init = r2300_pgd_init;
Index: linux/arch/mips/mm/r4xx0.c
diff -u linux/arch/mips/mm/r4xx0.c:1.29 linux/arch/mips/mm/r4xx0.c:1.30
--- linux/arch/mips/mm/r4xx0.c:1.29 Wed Oct 14 22:29:59 1998
+++ linux/arch/mips/mm/r4xx0.c Fri Oct 16 21:22:43 1998
@@ -1,4 +1,4 @@
-/* $Id: r4xx0.c,v 1.29 1998/10/14 20:29:59 ralf Exp $
+/* $Id: r4xx0.c,v 1.30 1998/10/16 19:22:43 ralf Exp $
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
@@ -2791,6 +2791,7 @@
flush_tlb_mm = r4k_flush_tlb_mm;
flush_tlb_range = r4k_flush_tlb_range;
flush_tlb_page = r4k_flush_tlb_page;
+ r4xx0_asid_setup();
load_pgd = r4k_load_pgd;
pgd_init = r4k_pgd_init;
Index: linux/arch/mips/mm/r6000.c
diff -u linux/arch/mips/mm/r6000.c:1.5 linux/arch/mips/mm/r6000.c:1.6
--- linux/arch/mips/mm/r6000.c:1.5 Tue Aug 18 22:45:09 1998
+++ linux/arch/mips/mm/r6000.c Fri Oct 16 21:22:44 1998
@@ -1,4 +1,5 @@
-/* $Id: r6000.c,v 1.5 1998/08/18 20:45:09 ralf Exp $
+/* $Id: r6000.c,v 1.6 1998/10/16 19:22:44 ralf Exp $
+ *
* r6000.c: MMU and cache routines for the R6000 processors.
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
@@ -13,6 +14,7 @@
#include <asm/pgtable.h>
#include <asm/system.h>
#include <asm/sgialib.h>
+#include <asm/mmu_context.h>
__asm__(".set mips3"); /* because we know... */
@@ -180,6 +182,7 @@
flush_tlb_mm = r6000_flush_tlb_mm;
flush_tlb_range = r6000_flush_tlb_range;
flush_tlb_page = r6000_flush_tlb_page;
+ r6000_asid_setup();
load_pgd = r6000_load_pgd;
pgd_init = r6000_pgd_init;
Index: linux/arch/mips/mm/tfp.c
diff -u linux/arch/mips/mm/tfp.c:1.5 linux/arch/mips/mm/tfp.c:1.6
--- linux/arch/mips/mm/tfp.c:1.5 Fri May 1 08:31:34 1998
+++ linux/arch/mips/mm/tfp.c Fri Oct 16 21:22:44 1998
@@ -1,4 +1,5 @@
-/*
+/* $Id: tfp.c,v 1.6 1998/10/16 19:22:44 ralf Exp $
+ *
* tfp.c: MMU and cache routines specific to the r8000 (TFP).
*
* Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
@@ -13,6 +14,7 @@
#include <asm/pgtable.h>
#include <asm/system.h>
#include <asm/sgialib.h>
+#include <asm/mmu_context.h>
extern unsigned long mips_tlb_entries;
@@ -104,6 +106,7 @@
flush_tlb_mm = tfp_flush_tlb_mm;
flush_tlb_range = tfp_flush_tlb_range;
flush_tlb_page = tfp_flush_tlb_page;
+ tfp_asid_setup();
add_wired_entry = tfp_add_wired_entry;
Index: linux/include/asm-mips/mmu_context.h
diff -u linux/include/asm-mips/mmu_context.h:1.2 linux/include/asm-mips/mmu_context.h:1.3
--- linux/include/asm-mips/mmu_context.h:1.2 Tue May 5 12:22:01 1998
+++ linux/include/asm-mips/mmu_context.h Fri Oct 16 21:22:54 1998
@@ -1,4 +1,4 @@
-/* $Id: mmu_context.h,v 1.2 1998/05/05 10:22:01 ralf Exp $
+/* $Id: mmu_context.h,v 1.3 1998/10/16 19:22:54 ralf Exp $
*
* Switch a MMU context.
*
@@ -11,29 +11,61 @@
#ifndef __ASM_MIPS_MMU_CONTEXT_H
#define __ASM_MIPS_MMU_CONTEXT_H
-#define MAX_ASID 255
-
+/* Fuck. The f-word is here so you can grep for it :-) */
extern unsigned long asid_cache;
-#define ASID_VERSION_SHIFT 16
-#define ASID_VERSION_MASK ((~0UL) << ASID_VERSION_SHIFT)
-#define ASID_FIRST_VERSION (1UL << ASID_VERSION_SHIFT)
-
-extern inline void get_new_mmu_context(struct mm_struct *mm, unsigned long asid)
-{
- /* check if it's legal.. */
- if ((asid & ~ASID_VERSION_MASK) > MAX_ASID) {
- /* start a new version, invalidate all old asid's */
- flush_tlb_all();
- asid = (asid & ASID_VERSION_MASK) + ASID_FIRST_VERSION;
- if (!asid)
+/* I patch, therefore I am ... */
+#define ASID_INC(asid) \
+ ({ unsigned long __asid = asid; \
+ __asm__("1:\taddiu\t%0,0\t\t\t\t# patched\n\t" \
+ ".section\t__asid_inc,\"a\"\n\t" \
+ ".word\t1b\n\t" \
+ ".previous" \
+ :"=r" (__asid) \
+ :"0" (__asid)); \
+ __asid; })
+#define ASID_MASK(asid) \
+ ({ unsigned long __asid = asid; \
+ __asm__("1:\tandi\t%0,%1,0\t\t\t# patched\n\t" \
+ ".section\t__asid_mask,\"a\"\n\t" \
+ ".word\t1b\n\t" \
+ ".previous" \
+ :"=r" (__asid) \
+ :"r" (__asid)); \
+ __asid; })
+#define ASID_VERSION_MASK \
+ ({ unsigned long __asid; \
+ __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t" \
+ ".section\t__asid_version_mask,\"a\"\n\t" \
+ ".word\t1b\n\t" \
+ ".previous" \
+ :"=r" (__asid)); \
+ __asid; })
+#define ASID_FIRST_VERSION \
+ ({ unsigned long __asid = asid; \
+ __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t" \
+ ".section\t__asid_first_version,\"a\"\n\t" \
+ ".word\t1b\n\t" \
+ ".previous" \
+ :"=r" (__asid)); \
+ __asid; })
+
+#define ASID_FIRST_VERSION_R3000 0x1000
+#define ASID_FIRST_VERSION_R4000 0x100
+
+extern inline void
+get_new_mmu_context(struct mm_struct *mm, unsigned long asid)
+{
+ if (!ASID_MASK((asid = ASID_INC(asid)))) {
+ flush_tlb_all(); /* start new asid cycle */
+ if (!asid) /* fix version if needed */
asid = ASID_FIRST_VERSION;
}
- asid_cache = asid + 1;
- mm->context = asid; /* full version + asid */
+ mm->context = asid_cache = asid;
}
-extern inline void get_mmu_context(struct task_struct *p)
+extern inline void
+get_mmu_context(struct task_struct *p)
{
struct mm_struct *mm = p->mm;
@@ -72,5 +104,31 @@
get_mmu_context(tsk);
set_entryhi(tsk->mm->context);
}
+
+extern void __asid_setup(unsigned int inc, unsigned int mask,
+ unsigned int version_mask, unsigned int first_version);
+
+extern inline void r3000_asid_setup(void)
+{
+ __asid_setup(0x40, 0xfc0, 0xf000, ASID_FIRST_VERSION_R3000);
+}
+
+extern inline void r6000_asid_setup(void)
+{
+ panic("r6000_asid_setup: implement me"); /* No idea ... */
+}
+
+extern inline void tfp_asid_setup(void)
+{
+ panic("tfp_asid_setup: implement me"); /* No idea ... */
+}
+
+extern inline void r4xx0_asid_setup(void)
+{
+ __asid_setup(1, 0xff, 0xff00, ASID_FIRST_VERSION_R4000);
+}
+
+/* R10000 has the same ASID mechanism as the R4000. */
+#define andes_asid_setup r4xx0_asid_setup
#endif /* __ASM_MIPS_MMU_CONTEXT_H */
next prev parent reply other threads:[~1998-10-17 1:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-13 19:59 get_mmu_context() ralf
[not found] ` <Pine.LNX.3.96.981014144230.10483B-100000@mirkwood.dummy.home>
1998-10-14 23:49 ` get_mmu_context() ralf
[not found] ` <3625D799.7D923FA9@niisi.msk.ru>
1998-10-15 20:21 ` get_mmu_context() ralf
[not found] ` <Pine.SV4.3.91.981016185136.876A-100000@mech.math.msu.su>
1998-10-18 19:53 ` get_mmu_context() Harald Koerfgen
1998-10-19 10:18 ` get_mmu_context() ralf
1998-10-20 4:07 ` get_mmu_context() Warner Losh
1998-10-20 17:31 ` get_mmu_context() ralf
1998-10-20 23:36 ` get_mmu_context() Warner Losh
1998-10-21 19:31 ` get_mmu_context() Harald Koerfgen
1998-10-19 1:29 ` get_mmu_context() ralf
1998-10-16 22:44 ` ralf [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-10-20 4:21 get_mmu_context() Ariel Faigon
1998-10-20 4:21 ` get_mmu_context() Ariel Faigon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19981017004408.E3370@uni-koblenz.de \
--to=ralf@uni-koblenz.de \
--cc=linux-mips@fnet.fr \
--cc=linux-mips@vger.rutgers.edu \
--cc=linux@cthulhu.engr.sgi.com \
--cc=roganov@niisi.msk.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox