Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Apr 2003 12:10:05 -0700
From:      Peter Wemm <peter@wemm.org>
To:        "David Xu" <davidxu@freebsd.org>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: patch for %gs saving 
Message-ID:  <20030411191005.68C322A7EA@canning.wemm.org>
In-Reply-To: <012401c2ffef$e50657e0$f001a8c0@davidw2k> 

next in thread | previous in thread | raw e-mail | index | archive | help
"David Xu" wrote:
> 
> ----- Original Message -----=20
> From: "Peter Wemm" <peter@wemm.org>
> To: "David Xu" <davidxu@freebsd.org>
> Cc: <freebsd-threads@freebsd.org>
> Sent: Friday, April 11, 2003 1:37 PM
> Subject: Re: patch for %gs saving=20
> 
> 
> > "David Xu" wrote:
> > > Here is the patch for kernel to save %gs,
> > > it works well on my machine.
> > > http://people.freebsd.org/~davidxu/i386_gs.diff
> > > Daniel, is this the reason in your libpthread
> > > patch that doesn't use getcontext syscall ?
> >=20
> > To put some background on the issue, there is a reason why we did not
> > do this.  %gs is not used by the kernel, so it does not normally need =
> to
> > be saved and restored on every trap into the kernel.  Setting a =
> segment
> > register is Really Slow - measured in hundreds of clock cycles.
> >=20
> > So, we normally only touch %gs when we context switch to a different =
> process
> > that may have a different %gs.  Or when one of the context syscalls =
> wants
> > it changed.  We cannot avoid touching %fs because we use it for kernel
> > private data.  But if it wasn't for that, we wouldn't be touching
> > %fs for regular traps/syscalls/etc either.
> >=20
> > Bruce Evans understands this better than I do, I would suggest not =
> making
> > this change without talking about it with him first.
> >=20
> 
> Yes, I know loading a descriptor is slow, but in real world, such =
> optimization
> will be lost in real work noise. And setcontext syscall is broken by =
> this
> optimization, userland will fail to set his context in atomic operation,
> set pcb->gs =3D userland_gs does not work, so the cost is obviously, I =
> can optimize
> my patch to only save and restore %gs at trap and interrupt time,  when =
> entering
> kernel, I can always zero %gs because kernel does not use it, I think =
> this can
> reduce clock cycles at context switch, this might be better than current =
> code which
> loading %gs at every context switch.

Currently we only change %gs when switching one entire process to another
seperate process.  Your patch changes it so that it changes %gs on every
single fault/trap/syscall/etc.  I regularly see process traces where
the ratio of syscalls to context switches is over 1000 to 1.  ie: your
patch would increase the cost of the %gs activity over a thousand times.

Cheers,
-Peter
--
Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com
"All of this is for nothing if we don't go to the stars" - JMS/B5



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030411191005.68C322A7EA>