Skip to content

Commit 63eca94

Browse files
committed
ARC: [SMP] ASID allocation
-Track a Per CPU ASID counter -mm-per-cpu ASID (multiple threads, or mm migrated around) Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent b6fe8e7 commit 63eca94

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#ifndef __ASSEMBLY__
4949

5050
typedef struct {
51-
unsigned long asid; /* 8 bit MMU PID + Generation cycle */
51+
unsigned long asid[NR_CPUS]; /* 8 bit MMU PID + Generation cycle */
5252
} mm_context_t;
5353

5454
#ifdef CONFIG_ARC_DBG_TLB_PARANOIA

‎arch/arc/include/asm/mmu_context.h‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
* "Fast Context Switch" i.e. no TLB flush on ctxt-switch
3131
*
3232
* Linux assigns each task a unique ASID. A simple round-robin allocation
33-
* of H/w ASID is done using software tracker @asid_cache.
33+
* of H/w ASID is done using software tracker @asid_cpu.
3434
* When it reaches max 255, the allocation cycle starts afresh by flushing
3535
* the entire TLB and wrapping ASID back to zero.
3636
*
3737
* A new allocation cycle, post rollover, could potentially reassign an ASID
3838
* to a different task. Thus the rule is to refresh the ASID in a new cycle.
39-
* The 32 bit @asid_cache (and mm->asid) have 8 bits MMU PID and rest 24 bits
39+
* The 32 bit @asid_cpu (and mm->asid) have 8 bits MMU PID and rest 24 bits
4040
* serve as cycle/generation indicator and natural 32 bit unsigned math
4141
* automagically increments the generation when lower 8 bits rollover.
4242
*/
@@ -47,16 +47,19 @@
4747
#define MM_CTXT_FIRST_CYCLE (MM_CTXT_ASID_MASK + 1)
4848
#define MM_CTXT_NO_ASID 0UL
4949

50-
#define hw_pid(mm) (mm->context.asid & MM_CTXT_ASID_MASK)
50+
#define asid_mm(mm, cpu) mm->context.asid[cpu]
51+
#define hw_pid(mm, cpu) (asid_mm(mm, cpu) & MM_CTXT_ASID_MASK)
5152

52-
extern unsigned int asid_cache;
53+
DECLARE_PER_CPU(unsigned int, asid_cache);
54+
#define asid_cpu(cpu) per_cpu(asid_cache, cpu)
5355

5456
/*
5557
* Get a new ASID if task doesn't have a valid one (unalloc or from prev cycle)
5658
* Also set the MMU PID register to existing/updated ASID
5759
*/
5860
static inline void get_new_mmu_context(struct mm_struct *mm)
5961
{
62+
const unsigned int cpu = smp_processor_id();
6063
unsigned long flags;
6164

6265
local_irq_save(flags);
@@ -71,11 +74,11 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
7174
* first need to destroy the context, setting it to invalid
7275
* value.
7376
*/
74-
if (!((mm->context.asid ^ asid_cache) & MM_CTXT_CYCLE_MASK))
77+
if (!((asid_mm(mm, cpu) ^ asid_cpu(cpu)) & MM_CTXT_CYCLE_MASK))
7578
goto set_hw;
7679

7780
/* move to new ASID and handle rollover */
78-
if (unlikely(!(++asid_cache & MM_CTXT_ASID_MASK))) {
81+
if (unlikely(!(++asid_cpu(cpu) & MM_CTXT_ASID_MASK))) {
7982

8083
flush_tlb_all();
8184

@@ -84,15 +87,15 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
8487
* If the container itself wrapped around, set it to a non zero
8588
* "generation" to distinguish from no context
8689
*/
87-
if (!asid_cache)
88-
asid_cache = MM_CTXT_FIRST_CYCLE;
90+
if (!asid_cpu(cpu))
91+
asid_cpu(cpu) = MM_CTXT_FIRST_CYCLE;
8992
}
9093

9194
/* Assign new ASID to tsk */
92-
mm->context.asid = asid_cache;
95+
asid_mm(mm, cpu) = asid_cpu(cpu);
9396

9497
set_hw:
95-
write_aux_reg(ARC_REG_PID, hw_pid(mm) | MMU_ENABLE);
98+
write_aux_reg(ARC_REG_PID, hw_pid(mm, cpu) | MMU_ENABLE);
9699

97100
local_irq_restore(flags);
98101
}
@@ -104,10 +107,24 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
104107
static inline int
105108
init_new_context(struct task_struct *tsk, struct mm_struct *mm)
106109
{
107-
mm->context.asid = MM_CTXT_NO_ASID;
110+
int i;
111+
112+
for_each_possible_cpu(i)
113+
asid_mm(mm, i) = MM_CTXT_NO_ASID;
114+
108115
return 0;
109116
}
110117

118+
static inline void destroy_context(struct mm_struct *mm)
119+
{
120+
unsigned long flags;
121+
122+
/* Needed to elide CONFIG_DEBUG_PREEMPT warning */
123+
local_irq_save(flags);
124+
asid_mm(mm, smp_processor_id()) = MM_CTXT_NO_ASID;
125+
local_irq_restore(flags);
126+
}
127+
111128
/* Prepare the MMU for task: setup PID reg with allocated ASID
112129
If task doesn't have an ASID (never alloc or stolen, get a new ASID)
113130
*/
@@ -131,11 +148,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
131148
*/
132149
#define activate_mm(prev, next) switch_mm(prev, next, NULL)
133150

134-
static inline void destroy_context(struct mm_struct *mm)
135-
{
136-
mm->context.asid = MM_CTXT_NO_ASID;
137-
}
138-
139151
/* it seemed that deactivate_mm( ) is a reasonable place to do book-keeping
140152
* for retiring-mm. However destroy_context( ) still needs to do that because
141153
* between mm_release( ) = >deactive_mm( ) and

‎arch/arc/mm/tlb.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101

102102
/* A copy of the ASID from the PID reg is kept in asid_cache */
103-
unsigned int asid_cache = MM_CTXT_FIRST_CYCLE;
103+
DEFINE_PER_CPU(unsigned int, asid_cache) = MM_CTXT_FIRST_CYCLE;
104104

105105
/*
106106
* Utility Routine to erase a J-TLB entry
@@ -274,6 +274,7 @@ noinline void local_flush_tlb_mm(struct mm_struct *mm)
274274
void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
275275
unsigned long end)
276276
{
277+
const unsigned int cpu = smp_processor_id();
277278
unsigned long flags;
278279

279280
/* If range @start to @end is more than 32 TLB entries deep,
@@ -297,9 +298,9 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
297298

298299
local_irq_save(flags);
299300

300-
if (vma->vm_mm->context.asid != MM_CTXT_NO_ASID) {
301+
if (asid_mm(vma->vm_mm, cpu) != MM_CTXT_NO_ASID) {
301302
while (start < end) {
302-
tlb_entry_erase(start | hw_pid(vma->vm_mm));
303+
tlb_entry_erase(start | hw_pid(vma->vm_mm, cpu));
303304
start += PAGE_SIZE;
304305
}
305306
}
@@ -346,15 +347,16 @@ void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
346347

347348
void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
348349
{
350+
const unsigned int cpu = smp_processor_id();
349351
unsigned long flags;
350352

351353
/* Note that it is critical that interrupts are DISABLED between
352354
* checking the ASID and using it flush the TLB entry
353355
*/
354356
local_irq_save(flags);
355357

356-
if (vma->vm_mm->context.asid != MM_CTXT_NO_ASID) {
357-
tlb_entry_erase((page & PAGE_MASK) | hw_pid(vma->vm_mm));
358+
if (asid_mm(vma->vm_mm, cpu) != MM_CTXT_NO_ASID) {
359+
tlb_entry_erase((page & PAGE_MASK) | hw_pid(vma->vm_mm, cpu));
358360
utlb_invalidate();
359361
}
360362

@@ -400,7 +402,7 @@ void create_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
400402

401403
local_irq_save(flags);
402404

403-
tlb_paranoid_check(vma->vm_mm->context.asid, address);
405+
tlb_paranoid_check(asid_mm(vma->vm_mm, smp_processor_id()), address);
404406

405407
address &= PAGE_MASK;
406408

0 commit comments

Comments
 (0)