From owner-freebsd-current@FreeBSD.ORG Tue Nov 27 06:41:54 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2A9C72F0 for ; Tue, 27 Nov 2012 06:41:54 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-ee0-f54.google.com (mail-ee0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9F3028FC15 for ; Tue, 27 Nov 2012 06:41:53 +0000 (UTC) Received: by mail-ee0-f54.google.com with SMTP id c13so8322379eek.13 for ; Mon, 26 Nov 2012 22:41:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :x-gm-message-state; bh=U336UTJBAaVRA0FUGnYoVMWL471DFzrqhzVs8KPjE/I=; b=NKhTDAlDxbAFciIL/qOPPkFIszwi8ITjZgqklbBLBlwqwfdgAxXq1RafM94tm6v6WX d+/eHXPxg+Sg4UgxM3qGkK53KsnCxyi3c09R3kWaOzNfVZCnVoF05ZUHJBDIuTuMyQcw YaaOYJW86ikm9xY305yu/QQBpVGnf9Q1f0Yt/wM0Zv8EgSxA8HyEVlB+eatj3I5usDkL XsVAfm1c7ataa48j3NXVk658TCGgC78ZbqVdLMICP1GPOjMB6S0gdgGN5EjBrkKcxpjL 29VV0idlcH1pn2p8bNv3a2KXLhmtefZNA2MBz1RlBbgJuc3Vt2V+WLCa8bNbInNDzwve NOJQ== Received: by 10.14.172.195 with SMTP id t43mr54839412eel.17.1353998512407; Mon, 26 Nov 2012 22:41:52 -0800 (PST) Received: from zont-osx.local (ppp95-165-156-193.pppoe.spdop.ru. [95.165.156.193]) by mx.google.com with ESMTPS id g47sm38820020eeo.6.2012.11.26.22.41.51 (version=SSLv3 cipher=OTHER); Mon, 26 Nov 2012 22:41:51 -0800 (PST) Sender: Andrey Zonov Message-ID: <50B460AA.10300@FreeBSD.org> Date: Tue, 27 Nov 2012 10:41:46 +0400 From: Andrey Zonov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Luigi Rizzo Subject: Re: syscall cost freebsd vs linux ? References: <20121119193202.GA79496@onelab2.iet.unipi.it> In-Reply-To: <20121119193202.GA79496@onelab2.iet.unipi.it> X-Enigmail-Version: 1.4.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig4B6FF0D266D2224B99A3B167" X-Gm-Message-State: ALoCoQmCQqC3rrUmHDZyZiWK6mClK+6ytIJuZN8+OfRtm+6rzS2zTvLa2R97Qa8CyZY5D0l7Me0F Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Nov 2012 06:41:54 -0000 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--