From owner-freebsd-current@FreeBSD.ORG Fri Nov 4 02:01:07 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B02B8106566B for ; Fri, 4 Nov 2011 02:01:07 +0000 (UTC) (envelope-from cpghost@cordula.ws) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 637CF8FC08 for ; Fri, 4 Nov 2011 02:01:07 +0000 (UTC) Received: by qadb12 with SMTP id b12so277615qad.13 for ; Thu, 03 Nov 2011 19:01:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.164.74 with SMTP id yo10mr2439933obb.69.1320372065908; Thu, 03 Nov 2011 19:01:05 -0700 (PDT) Received: by 10.182.39.169 with HTTP; Thu, 3 Nov 2011 19:01:05 -0700 (PDT) X-Originating-IP: [93.221.165.185] In-Reply-To: <201110251454.00471.jhb@freebsd.org> References: <99483.1319566152@critter.freebsd.dk> <201110251454.00471.jhb@freebsd.org> Date: Fri, 4 Nov 2011 03:01:05 +0100 Message-ID: From: "C. P. Ghost" To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Poul-Henning Kamp , freebsd-current@freebsd.org, Luigi Rizzo Subject: Re: getting the cpuid for a userspace process ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Fri, 04 Nov 2011 02:01:07 -0000 On Tue, Oct 25, 2011 at 8:54 PM, John Baldwin wrote: > On Tuesday, October 25, 2011 2:09:12 pm Poul-Henning Kamp wrote: >> In message <201110251342.45194.jhb@freebsd.org>, John Baldwin writes: >> >On Tuesday, October 25, 2011 11:06:22 am Luigi Rizzo wrote: >> >> as the subject says... is there any way to get the current >> >> CPU id for a userspace process (of course, >> >> valid only at the time the function is called as the >> >> process might be arbitrarily moved while it runs) >> > >> >Not from userland, no. =A0On x86 you can use cpuid to fetch the APIC ID= , but >> >that does not map 1:1 to FreeBSD cpu IDs. >> >> How does JEmalloc do it ? > > I don't think it does on FreeBSD. =A0The only thing malloc() knows on Fre= eBSD is > the total number of CPUs. =A0I believe Linux has a system call that retur= ns this > though (sched_getcpu() is the public interface which is a wrapper around = a > getcpu() system call). =A0From the manpage it would seem that sched_getcp= u() > uses a per-thread shared page of some sort so that it doesn't actually ha= ve to > enter the kernel to get the CPU ID. =A0Alternatively, you could imagine i= t on > x86 at least exporting a table mapping APIC IDs to CPU IDs and then using > cpuid and that table to do the lookup purely in userland. =A0That would o= nly > necessitate a global shared page and not one per-thread. =A0You could sti= ll fall > back to a system call for other architectures that simply returned > curthread->td_oncpu. Exposing a table mapping to userland would be somewhat similar to the way L4Ka::Pistachio exports a UTCB area to userland threads: https://github.com/l4ka/pistachio/blob/dd624dde5bce4ab120b2fcecbbcd94473eff= b201/kernel/src/glue/v4-x86/utcb.h > -- > John Baldwin -cpghost. --=20 Cordula's Web. http://www.cordula.ws/