blob: 9fbc6b20026b5ac4f23f9704e2cac9b1daaaf3a6 [file] [log] [blame]
Andi Kleen2aae9502007-07-21 17:10:01 +02001/*
2 * Copyright 2006 Andi Kleen, SUSE Labs.
3 * Subject to the GNU Public License, v.2
4 *
5 * Fast user context implementation of getcpu()
6 */
7
8#include <linux/kernel.h>
9#include <linux/getcpu.h>
10#include <linux/jiffies.h>
11#include <linux/time.h>
12#include <asm/vsyscall.h>
13#include <asm/vgtod.h>
14#include "vextern.h"
15
Steven Rostedt23adec52008-05-12 21:20:41 +020016notrace long
17__vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
Andi Kleen2aae9502007-07-21 17:10:01 +020018{
Glauber de Oliveira Costa8f12dea2008-01-30 13:31:06 +010019 unsigned int p;
Andi Kleen2aae9502007-07-21 17:10:01 +020020
Ingo Molnar4307d1e2007-11-07 18:37:48 +010021 if (*vdso_vgetcpu_mode == VGETCPU_RDTSCP) {
Andi Kleen2aae9502007-07-21 17:10:01 +020022 /* Load per CPU data from RDTSCP */
Glauber de Oliveira Costa8f12dea2008-01-30 13:31:06 +010023 native_read_tscp(&p);
Andi Kleen2aae9502007-07-21 17:10:01 +020024 } else {
25 /* Load per CPU data from GDT */
26 asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
27 }
Andi Kleen2aae9502007-07-21 17:10:01 +020028 if (cpu)
29 *cpu = p & 0xfff;
30 if (node)
31 *node = p >> 12;
32 return 0;
33}
34
35long getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
36 __attribute__((weak, alias("__vdso_getcpu")));