syscall cost freebsd vs linux ?

Andrey Zonov zont at FreeBSD.org
Tue Nov 27 06:41:54 UTC 2012


On 11/19/12 11:32 PM, Luigi Rizzo wrote:
> today i was comparing the performance of some netmap-related code
> on FreeBSD and Linux (RELENG_9 vs 3.2) and i was surprised to see that
> our system calls are significantly slower.
> On comparable hardware (i7-2600k vs E5-1650) the syscall
> getppid() takes about 95ns on FreeBSD and 38ns on linux.
> 
> (i make sure not to use gettimeofday(), which in linux is through vdso,
> and getpid(), which is cached by glibc).
> 
> Any idea on why there is this difference and whether/how
> we can reduce it ?
> 

This is the cost of blocking mutexes.  Linux uses RCU instead [1].

Here are the numbers on current:

$ time ./getppid 100000000

real	0m22.926s
user	0m2.252s
sys	0m20.669s

After locking removing (patch below):

$ time ./getppid 100000000

real	0m15.224s
user	0m2.355s
sys	0m12.868s

Unfortunately, RCU can be used only in GPL code, but we can use "passive
serialization" for simple deref.  And even more, it's already
implemented in NetBSD.


[1]
https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=kernel/timer.c;h=367d008584823a6fe01ed013cda8c3693fcfd761;hb=HEAD#l1411
[2]
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/subr_pserialize.c?rev=1.5&content-type=text/x-cvsweb-markup

diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 7c46b2d..a13a17c 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -123,9 +123,7 @@ sys_getppid(struct thread *td, struct getppid_args *uap)
 {
        struct proc *p = td->td_proc;

-       PROC_LOCK(p);
        td->td_retval[0] = p->p_pptr->p_pid;
-       PROC_UNLOCK(p);
        return (0);
 }


-- 
Andrey Zonov

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 535 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-current/attachments/20121127/d688799d/attachment.sig>


More information about the freebsd-current mailing list