switch_to.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Low-level task switching. This is based on information published in
  3. * the Processor Abstraction Layer and the System Abstraction Layer
  4. * manual.
  5. *
  6. * Copyright (C) 1998-2003 Hewlett-Packard Co
  7. * David Mosberger-Tang <davidm@hpl.hp.com>
  8. * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
  9. * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
  10. */
  11. #ifndef _ASM_IA64_SWITCH_TO_H
  12. #define _ASM_IA64_SWITCH_TO_H
  13. #include <linux/percpu.h>
  14. struct task_struct;
  15. /*
  16. * Context switch from one thread to another. If the two threads have
  17. * different address spaces, schedule() has already taken care of
  18. * switching to the new address space by calling switch_mm().
  19. *
  20. * Disabling access to the fph partition and the debug-register
  21. * context switch MUST be done before calling ia64_switch_to() since a
  22. * newly created thread returns directly to
  23. * ia64_ret_from_syscall_clear_r8.
  24. */
  25. extern struct task_struct *ia64_switch_to (void *next_task);
  26. extern void ia64_save_extra (struct task_struct *task);
  27. extern void ia64_load_extra (struct task_struct *task);
  28. #ifdef CONFIG_PERFMON
  29. DECLARE_PER_CPU(unsigned long, pfm_syst_info);
  30. # define PERFMON_IS_SYSWIDE() (__this_cpu_read(pfm_syst_info) & 0x1)
  31. #else
  32. # define PERFMON_IS_SYSWIDE() (0)
  33. #endif
  34. #define IA64_HAS_EXTRA_STATE(t) \
  35. ((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID) \
  36. || PERFMON_IS_SYSWIDE())
  37. #define __switch_to(prev,next,last) do { \
  38. if (IA64_HAS_EXTRA_STATE(prev)) \
  39. ia64_save_extra(prev); \
  40. if (IA64_HAS_EXTRA_STATE(next)) \
  41. ia64_load_extra(next); \
  42. ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next); \
  43. (last) = ia64_switch_to((next)); \
  44. } while (0)
  45. #ifdef CONFIG_SMP
  46. /*
  47. * In the SMP case, we save the fph state when context-switching away from a thread that
  48. * modified fph. This way, when the thread gets scheduled on another CPU, the CPU can
  49. * pick up the state from task->thread.fph, avoiding the complication of having to fetch
  50. * the latest fph state from another CPU. In other words: eager save, lazy restore.
  51. */
  52. # define switch_to(prev,next,last) do { \
  53. if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) { \
  54. ia64_psr(task_pt_regs(prev))->mfh = 0; \
  55. (prev)->thread.flags |= IA64_THREAD_FPH_VALID; \
  56. __ia64_save_fpu((prev)->thread.fph); \
  57. } \
  58. __switch_to(prev, next, last); \
  59. /* "next" in old context is "current" in new context */ \
  60. if (unlikely((current->thread.flags & IA64_THREAD_MIGRATION) && \
  61. (task_cpu(current) != \
  62. task_thread_info(current)->last_cpu))) { \
  63. platform_migrate(current); \
  64. task_thread_info(current)->last_cpu = task_cpu(current); \
  65. } \
  66. } while (0)
  67. #else
  68. # define switch_to(prev,next,last) __switch_to(prev, next, last)
  69. #endif
  70. #endif /* _ASM_IA64_SWITCH_TO_H */