Linux MIPS Architecture development
 help / color / mirror / Atom feed
* get_mmu_context()
@ 1998-10-13 19:59 ralf
       [not found] ` <Pine.LNX.3.96.981014144230.10483B-100000@mirkwood.dummy.home>
       [not found] ` <3625D799.7D923FA9@niisi.msk.ru>
  0 siblings, 2 replies; 13+ messages in thread
From: ralf @ 1998-10-13 19:59 UTC (permalink / raw)
  To: Vladimir Roganov, linux-mips, linux, linux-mips, linux-kernel

Ok, here is a draft version of an agressively optimized version of
get_mmu_context().  I just didn't like the idea of referencing
global variables in get_mmu_context() if avoidable.  The code below
will work on both R3000 and R4000 with no performance penalty for
being generic.  The trick is to patch the operands of two machine
instructions at runtime, shoot me.

The code below should be integrated into <asm/mmu_context.h>.  The
CPU specific code in arch/mips/mm/... will then just have to include
that header file and call r3000_asid_setup rsp. r4xx0_asid_setup.

Have fun,

  Ralf

#define ASID_VERSION_SHIFT 16
#define ASID_VERSION_MASK  ((~0UL) << ASID_VERSION_SHIFT)
#define ASID_FIRST_VERSION (1UL << ASID_VERSION_SHIFT)

unsigned long asid_cache = ASID_FIRST_VERSION;

/* The next two macros know that they will only be assembled once
   per kernel.  */
#define ASID_VERSION_INC					\
 ({ unsigned long __asid_inc;					\
   __asm__(".globl\tasid_inc\n"					\
           "asid_inc:\n\t"					\
           "li\t%0,0\t\t\t#patched\n\t"				\
           :"=r" (__asid_inc));					\
   __asid_inc; })

#define ASID_OVERFLOW(asid)					\
 ({ unsigned long __res;					\
   __asm__(".global\tasid_overflow\n"				\
           "asid_overflow:\n\t"					\
           "sltu\t%0,%1,0\t\t\t#patched\n\t"			\
           :"=r" (__res)					\
           :"r" (asid));					\
   __res; })

extern inline void get_new_mmu_context(struct mm_struct *mm, unsigned long asid)
{
	/* check if it's legal.. */
	if (ASID_OVERFLOW(asid & ~ASID_VERSION_MASK)) {
		/* start a new version, invalidate all old asid's */
		flush_tlb_all();
		asid = (asid & ASID_VERSION_MASK) + ASID_FIRST_VERSION;
		if (!asid)
			asid = ASID_FIRST_VERSION;
	}
	asid_cache = asid + ASID_VERSION_INC;
	mm->context = asid;			 /* full version + asid */
}

extern void get_mmu_context(struct task_struct *p)
{
	struct mm_struct *mm = p->mm;

	if (mm) {
		unsigned long asid = asid_cache;
		/* Check if our ASID is of an older version and thus invalid */
		if ((mm->context ^ asid) & ASID_VERSION_MASK)
			get_new_mmu_context(mm, asid);
	}
}

extern inline void __asid_setup(unsigned long asid_inc, unsigned long asid_cmp)
{
	extern u32 asid_inc;
	extern u32 asid_overflow;

	asid_inc = (asid_inc & 0xffff0000) | asid_inc;
	flush_icache_range(&asid_inc, 4);
	asid_overflow = (asid_overflow & 0xffff0000) | asid_cmp;
	flush_icache_range(&asid_overflow, 4);
}

extern inline void r3000_asid_setup(void)
{
	__asid_setup(0x40, 0xfc1);
}

extern inline void r4xx0_asid_setup(void)
{
	__asid_setup(1, 0x100);
}

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: get_mmu_context()
@ 1998-10-20  4:21 Ariel Faigon
  1998-10-20  4:21 ` get_mmu_context() Ariel Faigon
  0 siblings, 1 reply; 13+ messages in thread
From: Ariel Faigon @ 1998-10-20  4:21 UTC (permalink / raw)
  To: SGI/Linux mailing list

Forwarding message from David, his email probably changed
so it bounced...

----- Forwarded message from owner-linux@cthulhu -----

From: "David S. Miller" <davem@dm.cobaltmicro.com>
To: imp@village.org
CC: ralf@uni-koblenz.de, linux-mips@fnet.fr, linux@cthulhu.engr.sgi.com
In-reply-to: <199810200407.WAA03233@harmony.village.org> (message from Warner
	Losh on Mon, 19 Oct 1998 22:07:26 -0600)
Subject: Re: get_mmu_context()
References: <19981019121804.F387@uni-koblenz.de>  <Pine.SV4.3.91.981016185136.876A-100000@mech.math.msu.su> <XFMail.981018215318.harald.koerfgen@netcologne.de> <199810200407.WAA03233@harmony.village.org>

   Date: Mon, 19 Oct 1998 22:07:26 -0600
   From: Warner Losh <imp@village.org>

   Wouldn't it be easier to have ld to have variant fixup records?
   That way you could patch all instances at run time, much like we do
   when we load stuff now...

See sparc32's btfixup in the kernel sources for the best
implementation I've ever seen.

Later,
David S. Miller
davem@dm.cobaltmicro.com

----- End of forwarded message from owner-linux@cthulhu -----

-- 
Peace, Ariel

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1998-10-21 19:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` get_mmu_context() ralf
  -- 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox