Skip to content

Commit bf9282d

Browse files
author
Peter Zijlstra
committed
cpuidle: Make CPUIDLE_FLAG_TLB_FLUSHED generic
This allows moving the leave_mm() call into generic code before rcu_idle_enter(). Gets rid of more trace_*_rcuidle() users. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Marco Elver <elver@google.com> Link: https://lkml.kernel.org/r/20200821085348.369441600@infradead.org
1 parent 1098582 commit bf9282d

6 files changed

Lines changed: 19 additions & 33 deletions

File tree

‎arch/x86/include/asm/mmu.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ typedef struct {
5959
}
6060

6161
void leave_mm(int cpu);
62+
#define leave_mm leave_mm
6263

6364
#endif /* _ASM_X86_MMU_H */

‎arch/x86/mm/tlb.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,12 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
555555
this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen);
556556
load_new_mm_cr3(next->pgd, new_asid, true);
557557

558-
/*
559-
* NB: This gets called via leave_mm() in the idle path
560-
* where RCU functions differently. Tracing normally
561-
* uses RCU, so we need to use the _rcuidle variant.
562-
*
563-
* (There is no good reason for this. The idle code should
564-
* be rearranged to call this before rcu_idle_enter().)
565-
*/
566-
trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
558+
trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
567559
} else {
568560
/* The new ASID is already up to date. */
569561
load_new_mm_cr3(next->pgd, new_asid, false);
570562

571-
/* See above wrt _rcuidle. */
572-
trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0);
563+
trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, 0);
573564
}
574565

575566
/* Make sure we write CR3 before loaded_mm. */

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/module.h>
2323
#include <linux/suspend.h>
2424
#include <linux/tick.h>
25+
#include <linux/mmu_context.h>
2526
#include <trace/events/power.h>
2627

2728
#include "cpuidle.h"
@@ -228,6 +229,9 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
228229
broadcast = false;
229230
}
230231

232+
if (target_state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
233+
leave_mm(dev->cpu);
234+
231235
/* Take note of the planned idle state. */
232236
sched_idle_set_state(target_state);
233237

‎drivers/idle/intel_idle.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ static unsigned int mwait_substates __initdata;
8989
*/
9090
#define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
9191

92-
/*
93-
* Set this flag for states where the HW flushes the TLB for us
94-
* and so we don't need cross-calls to keep it consistent.
95-
* If this flag is set, SW flushes the TLB, so even if the
96-
* HW doesn't do the flushing, this flag is safe to use.
97-
*/
98-
#define CPUIDLE_FLAG_TLB_FLUSHED BIT(16)
99-
10092
/*
10193
* MWAIT takes an 8-bit "hint" in EAX "suggesting"
10294
* the C-state (top nibble) and sub-state (bottom nibble)
@@ -131,14 +123,6 @@ static __cpuidle int intel_idle(struct cpuidle_device *dev,
131123
unsigned long eax = flg2MWAIT(state->flags);
132124
unsigned long ecx = 1; /* break on interrupt flag */
133125
bool tick;
134-
int cpu = smp_processor_id();
135-
136-
/*
137-
* leave_mm() to avoid costly and often unnecessary wakeups
138-
* for flushing the user TLB's associated with the active mm.
139-
*/
140-
if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
141-
leave_mm(cpu);
142126

143127
if (!static_cpu_has(X86_FEATURE_ARAT)) {
144128
/*

‎include/linux/cpuidle.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ struct cpuidle_state {
7575
};
7676

7777
/* Idle State Flags */
78-
#define CPUIDLE_FLAG_NONE (0x00)
79-
#define CPUIDLE_FLAG_POLLING BIT(0) /* polling state */
80-
#define CPUIDLE_FLAG_COUPLED BIT(1) /* state applies to multiple cpus */
81-
#define CPUIDLE_FLAG_TIMER_STOP BIT(2) /* timer is stopped on this state */
82-
#define CPUIDLE_FLAG_UNUSABLE BIT(3) /* avoid using this state */
83-
#define CPUIDLE_FLAG_OFF BIT(4) /* disable this state by default */
78+
#define CPUIDLE_FLAG_NONE (0x00)
79+
#define CPUIDLE_FLAG_POLLING BIT(0) /* polling state */
80+
#define CPUIDLE_FLAG_COUPLED BIT(1) /* state applies to multiple cpus */
81+
#define CPUIDLE_FLAG_TIMER_STOP BIT(2) /* timer is stopped on this state */
82+
#define CPUIDLE_FLAG_UNUSABLE BIT(3) /* avoid using this state */
83+
#define CPUIDLE_FLAG_OFF BIT(4) /* disable this state by default */
84+
#define CPUIDLE_FLAG_TLB_FLUSHED BIT(5) /* idle-state flushes TLBs */
8485

8586
struct cpuidle_device_kobj;
8687
struct cpuidle_state_kobj;

‎include/linux/mmu_context.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
#define _LINUX_MMU_CONTEXT_H
44

55
#include <asm/mmu_context.h>
6+
#include <asm/mmu.h>
67

78
/* Architectures that care about IRQ state in switch_mm can override this. */
89
#ifndef switch_mm_irqs_off
910
# define switch_mm_irqs_off switch_mm
1011
#endif
1112

13+
#ifndef leave_mm
14+
static inline void leave_mm(int cpu) { }
15+
#endif
16+
1217
#endif

0 commit comments

Comments
 (0)