mmu_context_32.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __I386_SCHED_H
  2. #define __I386_SCHED_H
  3. #include <asm/desc.h>
  4. #include <asm/atomic.h>
  5. #include <asm/pgalloc.h>
  6. #include <asm/tlbflush.h>
  7. #include <asm/paravirt.h>
  8. #ifndef CONFIG_PARAVIRT
  9. #include <asm-generic/mm_hooks.h>
  10. static inline void paravirt_activate_mm(struct mm_struct *prev,
  11. struct mm_struct *next)
  12. {
  13. }
  14. #endif /* !CONFIG_PARAVIRT */
  15. /*
  16. * Used for LDT copy/destruction.
  17. */
  18. int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  19. void destroy_context(struct mm_struct *mm);
  20. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  21. {
  22. #ifdef CONFIG_SMP
  23. unsigned cpu = smp_processor_id();
  24. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
  25. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY;
  26. #endif
  27. }
  28. void leave_mm(unsigned long cpu);
  29. static inline void switch_mm(struct mm_struct *prev,
  30. struct mm_struct *next,
  31. struct task_struct *tsk)
  32. {
  33. int cpu = smp_processor_id();
  34. if (likely(prev != next)) {
  35. /* stop flush ipis for the previous mm */
  36. cpu_clear(cpu, prev->cpu_vm_mask);
  37. #ifdef CONFIG_SMP
  38. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  39. per_cpu(cpu_tlbstate, cpu).active_mm = next;
  40. #endif
  41. cpu_set(cpu, next->cpu_vm_mask);
  42. /* Re-load page tables */
  43. load_cr3(next->pgd);
  44. /*
  45. * load the LDT, if the LDT is different:
  46. */
  47. if (unlikely(prev->context.ldt != next->context.ldt))
  48. load_LDT_nolock(&next->context);
  49. }
  50. #ifdef CONFIG_SMP
  51. else {
  52. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  53. BUG_ON(per_cpu(cpu_tlbstate, cpu).active_mm != next);
  54. if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
  55. /* We were in lazy tlb mode and leave_mm disabled
  56. * tlb flush IPI delivery. We must reload %cr3.
  57. */
  58. load_cr3(next->pgd);
  59. load_LDT_nolock(&next->context);
  60. }
  61. }
  62. #endif
  63. }
  64. #define deactivate_mm(tsk, mm) \
  65. asm("movl %0,%%gs": :"r" (0));
  66. #define activate_mm(prev, next) \
  67. do { \
  68. paravirt_activate_mm(prev, next); \
  69. switch_mm((prev),(next),NULL); \
  70. } while(0);
  71. #endif