From: Chuck Ebbert <76306.1226@compuserve.com>
To: Andi Kleen <ak@suse.de>
Cc: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC, patch] i386: vgetcpu()
Date: Tue, 20 Jun 2006 18:40:06 -0400 [thread overview]
Message-ID: <200606201842_MC3-1-C2FD-FB7E@compuserve.com> (raw)
In-Reply-To: <200606202257.16033.ak@suse.de>
On Tue, 20 Jun 2006 22:57:16 +0200, Andi Kleen wrote:
> On Tuesday 20 June 2006 22:25, Chuck Ebbert wrote:
> > Use the limit field of a GDT entry to store the current CPU
> > number for fast userspace access. This still leaves 12 bits
> > free for other information.
>
> Nice trick. Maybe I'll even add that to the x86-64 implementation
> if it's fast enough. Do you have numbers?
>
I got ~13 clocks on x86_64 and 21 on PII. Test program below.
> But it needs to be encapsulated in a wrapper I think. Just exposing
> it to user space is the wrong way to do this.
Well there's no real way to hide it, but something more is definitely
needed. A new vdso entry point is easy but how do you tell userspace
it's there? Does glibc look at the kernel version in the note?
/* test how fast lsl, test for success + mask result runs
* leave DO_TEST undefined to measure overhead
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#define rdtscll(t) asm volatile ("rdtsc" : "=A" (t))
#ifndef ITERS
#define ITERS 1000000
#endif
int main(int argc, char * const argv[])
{
unsigned long long tsc1, tsc2;
int count, cpu, junk;
rdtscll(tsc1);
asm (
" pushl %%ds \n"
" popl %2 \n"
"1: \n"
#ifdef DO_TEST
" lsl %2,%0 \n"
" jnz 2f \n"
" and $0xff,%0 \n"
#endif
" dec %1 \n"
" jnz 1b \n"
"2: \n"
: "=&r" (cpu), "=&r" (count), "=&r" (junk)
: "1" (ITERS), "0" (-1)
);
rdtscll(tsc2);
if (count == 0)
printf("loops: %d, avg: %llu clocks\n",
ITERS, (tsc2 - tsc1) / ITERS);
return 0;
}
--
Chuck
"You can't read a newspaper if you can't read." --George W. Bush
next reply other threads:[~2006-06-20 22:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-20 22:40 Chuck Ebbert [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-06-20 20:25 [RFC, patch] i386: vgetcpu() Chuck Ebbert
2006-06-20 20:57 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200606201842_MC3-1-C2FD-FB7E@compuserve.com \
--to=76306.1226@compuserve.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox