lkml.org 
[lkml]   [2006]   [Jun]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC, patch] i386: vgetcpu()
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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-06-21 00:47    [W:0.025 / U:0.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site