Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Jun 2012 10:26:10 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        Gianni <gianni@FreeBSD.org>, John Baldwin <jhb@FreeBSD.org>, Alan Cox <alc@rice.edu>, Alexander Kabaev <kan@FreeBSD.org>, Attilio Rao <attilio@FreeBSD.org>, Konstantin Belousov <kib@FreeBSD.org>, freebsd-arch@FreeBSD.org, Konstantin Belousov <kostikbel@gmail.com>
Subject:   Re: Fast vs slow syscalls (Re: Fwd: [RFC] Kernel shared variables)
Message-ID:  <86sje7sf31.fsf@ds4.des.no>
In-Reply-To: <20120607064951.C1106@besplex.bde.org> (Bruce Evans's message of "Thu, 7 Jun 2012 07:14:06 %2B1000 (EST)")
References:  <CACfq090r1tWhuDkxdSZ24fwafbVKU0yduu1yV2%2BoYo%2BwwT4ipA@mail.gmail.com> <201206051008.29568.jhb@freebsd.org> <86haupvk4a.fsf@ds4.des.no> <201206051222.12627.jhb@freebsd.org> <20120605171446.GA28387@onelab2.iet.unipi.it> <20120606040931.F1050@besplex.bde.org> <864nqovoek.fsf@ds4.des.no> <20120607064951.C1106@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans <brde@optusnet.com.au> writes:
> Now 2.44 nsec/call makes sense, but you really should add some volatiles
> here to ensure that getpid() is not optimized away.

As you can see from the disassembly I provided, it isn't.

> SO it loops OK, but we can't see what getpid() does.  It must not be
> doing much.

Umm, yes, that's the whole point of this conversation.  Linux's getpid()
is not a syscall, but a library function that returns a constant from a
page shared by the kernel.

> 5.4104 nsec/call for gettimeofday() is impossible if there is any
> rdtsc() hardware call or much layering.

It's gettimeofday(0, 0), actually, so it doesn't need to read the clock.
If I pass a struct timeval as the first argument - so it *does* need to
read the clock - it's a little bit slower but still faster than an
actual system call.  Here's another run that demonstrates this - a
little bit slower than previous runs because I have other processes
running:

getpid(): 10,000,000 iterations in 30,377 us
gettimeofday(0, 0): 10,000,000 iterations in 55,571 us
gettimeofday(&tv, 0): 10,000,000 iterations in 302,634 us
kill(pid, 0): 10,000,000 iterations in 1,291,793 us

I can't test a static build since RHEL6 does not provide a static libc.

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



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