Re: syscall cost freebsd vs linux ?

From: Andrey Zonov <zont_at_FreeBSD.org>
Date: Tue, 27 Nov 2012 10:41:46 +0400
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
_at__at_ -123,9 +123,7 _at__at_ 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


Received on Tue Nov 27 2012 - 05:41:54 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:32 UTC