From owner-freebsd-arch@FreeBSD.ORG Thu Jun 7 22:30:55 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 54CDC106566C for ; Thu, 7 Jun 2012 22:30:55 +0000 (UTC) (envelope-from peter@wemm.org) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 01EA18FC14 for ; Thu, 7 Jun 2012 22:30:54 +0000 (UTC) Received: by obcni5 with SMTP id ni5so1932921obc.13 for ; Thu, 07 Jun 2012 15:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wemm.org; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=i0JQgQZ9xYJMjfa7QQfX3eHxrZLrBlf9C2/DZE1+xNw=; b=Qx3F3jdux4RfHWpVEb+oJCyAwiTfn3EvPwaA+/PybhA/wZzAn7euLLjNkE/gHpLWgn luEGvpPtKkRKrw5bZISBSxlxLUQLb5tEI3CwXxUb4bRval0uw8gr35K1viseU3onNDj/ lpfogLsqS6QrwaEHraXgzr8kxuMmDDUWIqSD4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding:x-gm-message-state; bh=i0JQgQZ9xYJMjfa7QQfX3eHxrZLrBlf9C2/DZE1+xNw=; b=B+AhmlLpCfJH+7ouyzEWQ00B8AwvzdY68PGkrbwksgncxsvovtsSs9v5BmZXg0SLyR DgXEPoi5JKppkIgulOft7PCNo6bKdEIgQAczxuzZ7pXr0F1LJ8BIPnCQqIwMDyBNO80V Bj6xgm2KfoI0WzfIAI1vZasEQHy/otmwLBWJpjYzjk5AVPRZ4/wtL0kz86ssPSnEyOzv RQr+QSDCjDqMYw7D3/Kagonhf4jl3nl5Y18jM8wGTcZf4FHu+w4Ffp1pQwyWzNwPyZnZ GOIzMqYfmXuLp+OuHXL6IMruOsv4Xp7Je8KQoM4mPhBf1Me8AooemSPjHgvUbofIfCRc 7rVA== MIME-Version: 1.0 Received: by 10.182.115.7 with SMTP id jk7mr3954542obb.9.1339108254334; Thu, 07 Jun 2012 15:30:54 -0700 (PDT) Received: by 10.182.115.35 with HTTP; Thu, 7 Jun 2012 15:30:54 -0700 (PDT) In-Reply-To: <86sje7sf31.fsf@ds4.des.no> References: <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> <86sje7sf31.fsf@ds4.des.no> Date: Thu, 7 Jun 2012 15:30:54 -0700 Message-ID: From: Peter Wemm To: =?ISO-8859-1?Q?Dag=2DErling_Sm=F8rgrav?= Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQn4quNIkLzAfusqu3DVMtJHj7w619QSrnyXc6rIPAMjx9uWJOnRHKIDGOstWgL6MoMmbBqS X-Mailman-Approved-At: Thu, 07 Jun 2012 23:14:33 +0000 Cc: Gianni , Alan Cox , Alexander Kabaev , Attilio Rao , Konstantin Belousov , freebsd-arch@freebsd.org, Konstantin Belousov Subject: Re: Fast vs slow syscalls (Re: Fwd: [RFC] Kernel shared variables) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2012 22:30:55 -0000 On Thu, Jun 7, 2012 at 1:26 AM, Dag-Erling Sm=F8rgrav wrote: > Bruce Evans 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. =A0It must not be >> doing much. > > Umm, yes, that's the whole point of this conversation. =A0Linux's getpid(= ) > is not a syscall, but a library function that returns a constant from a > page shared by the kernel. It might be worth taking a peek at what they do before going too far down the rabbit hole. They've had to deal with the whole ABI stability vs kernel layout thing already. As I recall, they literally embed a userland style .so shared object into the kernel and make it available to the user. The dynamic linker "finds" it via elf auxinfo and inserts it into the symbol search order. That way, the shared page layout is kernel specific. If they chose to provide getpid() or gettimeofday() or whatever, its a matter of adjusting the shared page and inserting code into the .so file. If the page changes, the code changes. Think of what we do with signal trampolines except in a way ld-elf.so.1 can pull it into user space and gdb "sees" it as a .so file with debug info. I think I remember that they did the shared page thing and then switched to providing a stub .so file. --=20 Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJV "All of this is for nothing if we don't go to the stars" - JMS/B5 "If Java had true garbage collection, most programs would delete themselves upon execution." -- Robert Sewell