percpu.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_PERCPU_H
  15. #define _ASM_TILE_PERCPU_H
  16. register unsigned long my_cpu_offset_reg asm("tp");
  17. #ifdef CONFIG_PREEMPT
  18. /*
  19. * For full preemption, we can't just use the register variable
  20. * directly, since we need barrier() to hazard against it, causing the
  21. * compiler to reload anything computed from a previous "tp" value.
  22. * But we also don't want to use volatile asm, since we'd like the
  23. * compiler to be able to cache the value across multiple percpu reads.
  24. * So we use a fake stack read as a hazard against barrier().
  25. * The 'U' constraint is like 'm' but disallows postincrement.
  26. */
  27. static inline unsigned long __my_cpu_offset(void)
  28. {
  29. unsigned long tp;
  30. register unsigned long *sp asm("sp");
  31. asm("move %0, tp" : "=r" (tp) : "U" (*sp));
  32. return tp;
  33. }
  34. #define __my_cpu_offset __my_cpu_offset()
  35. #else
  36. /*
  37. * We don't need to hazard against barrier() since "tp" doesn't ever
  38. * change with PREEMPT_NONE, and with PREEMPT_VOLUNTARY it only
  39. * changes at function call points, at which we are already re-reading
  40. * the value of "tp" due to "my_cpu_offset_reg" being a global variable.
  41. */
  42. #define __my_cpu_offset my_cpu_offset_reg
  43. #endif
  44. #define set_my_cpu_offset(tp) (my_cpu_offset_reg = (tp))
  45. #include <asm-generic/percpu.h>
  46. #endif /* _ASM_TILE_PERCPU_H */