vgetcpu.c 825 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  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. #include <linux/kernel.h>
  8. #include <linux/getcpu.h>
  9. #include <linux/jiffies.h>
  10. #include <linux/time.h>
  11. #include <asm/vsyscall.h>
  12. #include <asm/vgtod.h>
  13. #include "vextern.h"
  14. notrace long
  15. __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
  16. {
  17. unsigned int p;
  18. if (*vdso_vgetcpu_mode == VGETCPU_RDTSCP) {
  19. /* Load per CPU data from RDTSCP */
  20. native_read_tscp(&p);
  21. } else {
  22. /* Load per CPU data from GDT */
  23. asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
  24. }
  25. if (cpu)
  26. *cpu = p & 0xfff;
  27. if (node)
  28. *node = p >> 12;
  29. return 0;
  30. }
  31. long getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
  32. __attribute__((weak, alias("__vdso_getcpu")));