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.
/* vgetcpu.c: get CPU number we are running on.
* Prints -1 if error occurred.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * const argv[])
{
int cpu;
asm (
" lsl %1,%0 \n" \
" jnz 2f \n" \
" and $0xff,%0 \n" \
"2: \n" \
: "=&r" (cpu)
: "r" ((27 << 3) | 3), "0" (-1)
);
printf("cpu: %d\n", cpu);
return 0;
}
Signed-off-by: Chuck Ebbert <[email protected]>
--- 2.6.17-32.orig/arch/i386/kernel/cpu/common.c
+++ 2.6.17-32/arch/i386/kernel/cpu/common.c
@@ -642,6 +642,9 @@ void __cpuinit cpu_init(void)
((((__u64)stk16_off) << 32) & 0xff00000000000000ULL) |
(CPU_16BIT_STACK_SIZE - 1);
+ /* Set up GDT entry for per-cpu data */
+ *(__u64 *)(&gdt[27]) |= cpu;
+
cpu_gdt_descr->size = GDT_SIZE - 1;
cpu_gdt_descr->address = (unsigned long)gdt;
--- 2.6.17-32.orig/arch/i386/kernel/head.S
+++ 2.6.17-32/arch/i386/kernel/head.S
@@ -525,7 +525,13 @@ ENTRY(cpu_gdt_table)
.quad 0x004092000000ffff /* 0xc8 APM DS data */
.quad 0x0000920000000000 /* 0xd0 - ESPFIX 16-bit SS */
- .quad 0x0000000000000000 /* 0xd8 - unused */
+
+ /*
+ * Use a GDT entry to store per-cpu data for user space (DPL 3.)
+ * 32-bit data segment, byte granularity, base 0, limit set at runtime.
+ */
+ .quad 0x0040f20000000000 /* 0xd8 - for per-cpu user data */
+
.quad 0x0000000000000000 /* 0xe0 - unused */
.quad 0x0000000000000000 /* 0xe8 - unused */
.quad 0x0000000000000000 /* 0xf0 - unused */
--
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]