Date: Tue, 27 Nov 2012 10:41:46 +0400 From: Andrey Zonov <zont@FreeBSD.org> To: Luigi Rizzo <rizzo@iet.unipi.it> Cc: current@freebsd.org Subject: Re: syscall cost freebsd vs linux ? Message-ID: <50B460AA.10300@FreeBSD.org> In-Reply-To: <20121119193202.GA79496@onelab2.iet.unipi.it> References: <20121119193202.GA79496@onelab2.iet.unipi.it>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4B6FF0D266D2224B99A3B167 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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. >=20 > (i make sure not to use gettimeofday(), which in linux is through vdso,= > and getpid(), which is cached by glibc). >=20 > Any idea on why there is this difference and whether/how > we can reduce it ? >=20 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=3Dlinux/kernel/git/torvalds/linux.git;a=3Dblob;= f=3Dkernel/timer.c;h=3D367d008584823a6fe01ed013cda8c3693fcfd761;hb=3DHEAD= #l1411 [2] http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/subr_pserialize.c?rev=3D= 1.5&content-type=3Dtext/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 *u= ap) { struct proc *p =3D td->td_proc; - PROC_LOCK(p); td->td_retval[0] =3D p->p_pptr->p_pid; - PROC_UNLOCK(p); return (0); } --=20 Andrey Zonov --------------enig4B6FF0D266D2224B99A3B167 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJQtGCuAAoJEBWLemxX/CvTwLAIAI2aQieB000ZXPe49SjnkVGd B6RtaVHDkvOCCEzu2U4x3C0Q0FdUvYwh+5eTOPGU0PQO3lrnKfObv7HAlYw0I38I Euru8zNO/QmbipED3Z8Yb7ejMOv12nLdAG3XlaWVKH14aMy5XEiZcvbQVJ4jJNAk lIKr9QCOt8W2hFrVZKyPS2DMjlY56dCMT7s94umUq/xgiurn7veuKexgAOg2V2Bj lvnpGgKs8lpWWeMEbIqD5wQS8W9lFOkWS8JceGScV/k3G6YwgFhi00yRamVbQQH8 sNGtWSqZ9BcspQjLtiMalV7griWrf9VAB50UxkqYz8cuyUkt8LH2J2Vqw1Upz44= =pYpH -----END PGP SIGNATURE----- --------------enig4B6FF0D266D2224B99A3B167--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50B460AA.10300>