Skip to content

Commit 35b9e0c

Browse files
atomic-kernel1Naim
authored andcommitted
x86/mm/tlb: Make enter_lazy_tlb() always inline on x86
enter_lazy_tlb() on x86 is short enough, and is called in context switching, which is the hot code path. Make enter_lazy_tlb() always inline on x86 to optimize performance. Cc: Thomas Gleixner <tglx@kernel.org> Cc: Rik van Riel <riel@surriel.com> Cc: David Hildenbrand (Red Hat) <david@kernel.org> Cc: Dave Hansen <dave.hansen@intel.com> Suggested-by: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Xie Yuanbin <qq570070308@gmail.com>
1 parent b92071c commit 35b9e0c

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

arch/x86/include/asm/mmu_context.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ static inline void mm_reset_untag_mask(struct mm_struct *mm)
136136
}
137137
#endif
138138

139-
#define enter_lazy_tlb enter_lazy_tlb
140-
extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk);
141-
142139
extern void mm_init_global_asid(struct mm_struct *mm);
143140
extern void mm_free_global_asid(struct mm_struct *mm);
144141

arch/x86/include/asm/tlbflush.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,28 @@ struct tlb_state_shared {
172172
};
173173
DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state_shared, cpu_tlbstate_shared);
174174

175+
/*
176+
* Please ignore the name of this function. It should be called
177+
* switch_to_kernel_thread().
178+
*
179+
* enter_lazy_tlb() is a hint from the scheduler that we are entering a
180+
* kernel thread or other context without an mm. Acceptable implementations
181+
* include doing nothing whatsoever, switching to init_mm, or various clever
182+
* lazy tricks to try to minimize TLB flushes.
183+
*
184+
* The scheduler reserves the right to call enter_lazy_tlb() several times
185+
* in a row. It will notify us that we're going back to a real mm by
186+
* calling switch_mm_irqs_off().
187+
*/
188+
#define enter_lazy_tlb enter_lazy_tlb
189+
static __always_inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
190+
{
191+
if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm)
192+
return;
193+
194+
this_cpu_write(cpu_tlbstate_shared.is_lazy, true);
195+
}
196+
175197
bool nmi_uaccess_okay(void);
176198
#define nmi_uaccess_okay nmi_uaccess_okay
177199

@@ -480,6 +502,10 @@ static inline void cpu_tlbstate_update_lam(unsigned long lam, u64 untag_mask)
480502
{
481503
}
482504
#endif
505+
#else /* !MODULE */
506+
#define enter_lazy_tlb enter_lazy_tlb
507+
extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
508+
__compiletime_error("enter_lazy_tlb() should not be used in modules");
483509
#endif /* !MODULE */
484510

485511
static inline void __native_tlb_flush_global(unsigned long cr4)

arch/x86/mm/tlb.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -971,27 +971,6 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next,
971971
}
972972
}
973973

974-
/*
975-
* Please ignore the name of this function. It should be called
976-
* switch_to_kernel_thread().
977-
*
978-
* enter_lazy_tlb() is a hint from the scheduler that we are entering a
979-
* kernel thread or other context without an mm. Acceptable implementations
980-
* include doing nothing whatsoever, switching to init_mm, or various clever
981-
* lazy tricks to try to minimize TLB flushes.
982-
*
983-
* The scheduler reserves the right to call enter_lazy_tlb() several times
984-
* in a row. It will notify us that we're going back to a real mm by
985-
* calling switch_mm_irqs_off().
986-
*/
987-
void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
988-
{
989-
if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm)
990-
return;
991-
992-
this_cpu_write(cpu_tlbstate_shared.is_lazy, true);
993-
}
994-
995974
/*
996975
* Using a temporary mm allows to set temporary mappings that are not accessible
997976
* by other CPUs. Such mappings are needed to perform sensitive memory writes

0 commit comments

Comments
 (0)