switch_to.h 2.9 KB

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