Re: current pointer question/suggestion

Alexander Kjeldaas (astor@guardian.no)
Mon, 20 Jul 1998 00:39:08 +0200


On Sun, Jul 19, 1998 at 06:03:49PM +0200, Alexander Kjeldaas wrote:
> On Sat, Jul 18, 1998 at 08:45:05PM -0400, Benjamin C.R. LaHaise wrote:
> >
> > And this just plain ain't gonna work on SMP (think of clone'd processes
> > that shared the same memory mapping). As for whether or not the effoer
> > worth it on UP is questionable.
> >
>
> I see. I guess the page would have to be per-cpu instead of
> per-process. And then it gets a bit hairy - I'm starting to have
> doubts myself. Oh well.. :-)
>

Ok. It gets hairy, but probably not impossible. You have to use the
global bit in the page table as Colin Plumb mentioned. You have one
page-table entry in the mm-struct that is reserved for "bogus"
use. Using the global bit, the actual contents of this entry doesn't
have to match the contents of the TLB entry of the CPU. You only use
this entry to _load_ this TLB entry on entry to the kernel.

Here's an outline of what you could do on a system call entry (SMP):

if current is a system-timeaholic, or
current->mm is not shared; then
# 1) this process uses a _lot_ of system calls, we find it best
# to allocate a static TLB entry pointing to current for this
# process, even when executing in user mode.
# _or_,
# 2) this process' mm isn't shared, so current->mm->special-entry is
# pointing to the correct current anyways
# ergo, do nothing
else
# thread
grab current->mm->special-entry-lock
current->mm->special-entry = %esp & ~8191
set global-flag on current->mm->special-entry
access __current
release current->mm->special-entry-lock
end

..and then on exit:

if current is a system-timeaholic, or
current->mm is not shared; then
# nothing
else
# thread
grab current->mm->special-entry-lock
remove global flag from current->mm->special-entry
invalidate __current TLB entry
release current->mm->special-entry-lock
end

The "system-timeaholic" flag is just something that could be used if
we have a thread that is using most of its time in the kernel.

astor

-- 
 Alexander Kjeldaas, Guardian Networks AS, Trondheim, Norway
 http://www.guardian.no/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html