Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __I386_SCHED_H |
| 2 | #define __I386_SCHED_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <asm/desc.h> |
| 5 | #include <asm/atomic.h> |
| 6 | #include <asm/pgalloc.h> |
| 7 | #include <asm/tlbflush.h> |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 8 | #include <asm/paravirt.h> |
| 9 | #ifndef CONFIG_PARAVIRT |
| 10 | #include <asm-generic/mm_hooks.h> |
| 11 | |
| 12 | static inline void paravirt_activate_mm(struct mm_struct *prev, |
| 13 | struct mm_struct *next) |
| 14 | { |
| 15 | } |
| 16 | #endif /* !CONFIG_PARAVIRT */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Used for LDT copy/destruction. |
| 21 | */ |
| 22 | int init_new_context(struct task_struct *tsk, struct mm_struct *mm); |
| 23 | void destroy_context(struct mm_struct *mm); |
| 24 | |
| 25 | |
| 26 | static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) |
| 27 | { |
| 28 | #ifdef CONFIG_SMP |
| 29 | unsigned cpu = smp_processor_id(); |
| 30 | if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK) |
| 31 | per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY; |
| 32 | #endif |
| 33 | } |
| 34 | |
| 35 | static inline void switch_mm(struct mm_struct *prev, |
| 36 | struct mm_struct *next, |
| 37 | struct task_struct *tsk) |
| 38 | { |
| 39 | int cpu = smp_processor_id(); |
| 40 | |
| 41 | if (likely(prev != next)) { |
| 42 | /* stop flush ipis for the previous mm */ |
| 43 | cpu_clear(cpu, prev->cpu_vm_mask); |
| 44 | #ifdef CONFIG_SMP |
| 45 | per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK; |
| 46 | per_cpu(cpu_tlbstate, cpu).active_mm = next; |
| 47 | #endif |
| 48 | cpu_set(cpu, next->cpu_vm_mask); |
| 49 | |
| 50 | /* Re-load page tables */ |
| 51 | load_cr3(next->pgd); |
| 52 | |
| 53 | /* |
| 54 | * load the LDT, if the LDT is different: |
| 55 | */ |
| 56 | if (unlikely(prev->context.ldt != next->context.ldt)) |
Jeremy Fitzhardinge | e5e3a04 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 57 | load_LDT_nolock(&next->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | #ifdef CONFIG_SMP |
| 60 | else { |
| 61 | per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK; |
| 62 | BUG_ON(per_cpu(cpu_tlbstate, cpu).active_mm != next); |
| 63 | |
| 64 | if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) { |
Joe Perches | 55464da | 2008-03-23 01:02:42 -0700 | [diff] [blame] | 65 | /* We were in lazy tlb mode and leave_mm disabled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * tlb flush IPI delivery. We must reload %cr3. |
| 67 | */ |
| 68 | load_cr3(next->pgd); |
Jeremy Fitzhardinge | e5e3a04 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 69 | load_LDT_nolock(&next->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | #endif |
| 73 | } |
| 74 | |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 75 | #define deactivate_mm(tsk, mm) \ |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 76 | asm("movl %0,%%gs": :"r" (0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Joe Perches | 55464da | 2008-03-23 01:02:42 -0700 | [diff] [blame] | 78 | #define activate_mm(prev, next) \ |
| 79 | do { \ |
| 80 | paravirt_activate_mm((prev), (next)); \ |
| 81 | switch_mm((prev), (next), NULL); \ |
| 82 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | #endif |