vgetcpu.c 804 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. notrace long
  14. __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
  15. {
  16. unsigned int p;
  17. if (VVAR(vgetcpu_mode) == VGETCPU_RDTSCP) {
  18. /* Load per CPU data from RDTSCP */
  19. native_read_tscp(&p);
  20. } else {
  21. /* Load per CPU data from GDT */
  22. asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
  23. }
  24. if (cpu)
  25. *cpu = p & 0xfff;
  26. if (node)
  27. *node = p >> 12;
  28. return 0;
  29. }
  30. long getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
  31. __attribute__((weak, alias("__vdso_getcpu")));