📄 smp.c
字号:
/* * linux/arch/m32r/kernel/smp.c * * M32R SMP support routines. * * Copyright (c) 2001, 2002 Hitoshi Yamamoto * * Taken from i386 version. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com> * * This code is released under the GNU General Public License version 2 or * later. */#undef DEBUG_SMP#include <linux/irq.h>#include <linux/interrupt.h>#include <linux/spinlock.h>#include <linux/mm.h>#include <linux/smp.h>#include <linux/profile.h>#include <linux/cpu.h>#include <asm/cacheflush.h>#include <asm/pgalloc.h>#include <asm/atomic.h>#include <asm/io.h>#include <asm/mmu_context.h>#include <asm/m32r.h>/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* Data structures and variables *//*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* * Structure and data for smp_call_function(). This is designed to minimise * static memory requirements. It also looks cleaner. */static DEFINE_SPINLOCK(call_lock);struct call_data_struct { void (*func) (void *info); void *info; atomic_t started; atomic_t finished; int wait;} __attribute__ ((__aligned__(SMP_CACHE_BYTES)));static struct call_data_struct *call_data;/* * For flush_cache_all() */static DEFINE_SPINLOCK(flushcache_lock);static volatile unsigned long flushcache_cpumask = 0;/* * For flush_tlb_others() */static volatile cpumask_t flush_cpumask;static struct mm_struct *flush_mm;static struct vm_area_struct *flush_vma;static volatile unsigned long flush_va;static DEFINE_SPINLOCK(tlbstate_lock);#define FLUSH_ALL 0xffffffffDECLARE_PER_CPU(int, prof_multiplier);DECLARE_PER_CPU(int, prof_old_multiplier);DECLARE_PER_CPU(int, prof_counter);extern spinlock_t ipi_lock[];/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* Function Prototypes *//*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/void smp_send_reschedule(int);void smp_reschedule_interrupt(void);void smp_flush_cache_all(void);void smp_flush_cache_all_interrupt(void);void smp_flush_tlb_all(void);static void flush_tlb_all_ipi(void *);void smp_flush_tlb_mm(struct mm_struct *);void smp_flush_tlb_range(struct vm_area_struct *, unsigned long, \ unsigned long);void smp_flush_tlb_page(struct vm_area_struct *, unsigned long);static void flush_tlb_others(cpumask_t, struct mm_struct *, struct vm_area_struct *, unsigned long);void smp_invalidate_interrupt(void);void smp_send_stop(void);static void stop_this_cpu(void *);int smp_call_function(void (*) (void *), void *, int, int);void smp_call_function_interrupt(void);void smp_send_timer(void);void smp_ipi_timer_interrupt(struct pt_regs *);void smp_local_timer_interrupt(struct pt_regs *);void send_IPI_allbutself(int, int);static void send_IPI_mask(cpumask_t, int, int);unsigned long send_IPI_mask_phys(cpumask_t, int, int);/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* Rescheduling request Routines *//*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//*==========================================================================* * Name: smp_send_reschedule * * Description: This routine requests other CPU to execute rescheduling. * 1.Send 'RESCHEDULE_IPI' to other CPU. * Request other CPU to execute 'smp_reschedule_interrupt()'. * * Born on Date: 2002.02.05 * * Arguments: cpu_id - Target CPU ID * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_send_reschedule(int cpu_id){ WARN_ON(cpu_is_offline(cpu_id)); send_IPI_mask(cpumask_of_cpu(cpu_id), RESCHEDULE_IPI, 1);}/*==========================================================================* * Name: smp_reschedule_interrupt * * Description: This routine executes on CPU which received * 'RESCHEDULE_IPI'. * Rescheduling is processed at the exit of interrupt * operation. * * Born on Date: 2002.02.05 * * Arguments: NONE * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_reschedule_interrupt(void){ /* nothing to do */}/*==========================================================================* * Name: smp_flush_cache_all * * Description: This routine sends a 'INVALIDATE_CACHE_IPI' to all other * CPUs in the system. * * Born on Date: 2003-05-28 * * Arguments: NONE * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_flush_cache_all(void){ cpumask_t cpumask; unsigned long *mask; preempt_disable(); cpumask = cpu_online_map; cpu_clear(smp_processor_id(), cpumask); spin_lock(&flushcache_lock); mask=cpus_addr(cpumask); atomic_set_mask(*mask, (atomic_t *)&flushcache_cpumask); send_IPI_mask(cpumask, INVALIDATE_CACHE_IPI, 0); _flush_cache_copyback_all(); while (flushcache_cpumask) mb(); spin_unlock(&flushcache_lock); preempt_enable();}void smp_flush_cache_all_interrupt(void){ _flush_cache_copyback_all(); clear_bit(smp_processor_id(), &flushcache_cpumask);}/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* TLB flush request Routins *//*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//*==========================================================================* * Name: smp_flush_tlb_all * * Description: This routine flushes all processes TLBs. * 1.Request other CPU to execute 'flush_tlb_all_ipi()'. * 2.Execute 'do_flush_tlb_all_local()'. * * Born on Date: 2002.02.05 * * Arguments: NONE * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_flush_tlb_all(void){ unsigned long flags; preempt_disable(); local_irq_save(flags); __flush_tlb_all(); local_irq_restore(flags); smp_call_function(flush_tlb_all_ipi, 0, 1, 1); preempt_enable();}/*==========================================================================* * Name: flush_tlb_all_ipi * * Description: This routine flushes all local TLBs. * 1.Execute 'do_flush_tlb_all_local()'. * * Born on Date: 2002.02.05 * * Arguments: *info - not used * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/static void flush_tlb_all_ipi(void *info){ __flush_tlb_all();}/*==========================================================================* * Name: smp_flush_tlb_mm * * Description: This routine flushes the specified mm context TLB's. * * Born on Date: 2002.02.05 * * Arguments: *mm - a pointer to the mm struct for flush TLB * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_flush_tlb_mm(struct mm_struct *mm){ int cpu_id; cpumask_t cpu_mask; unsigned long *mmc; unsigned long flags; preempt_disable(); cpu_id = smp_processor_id(); mmc = &mm->context[cpu_id]; cpu_mask = mm->cpu_vm_mask; cpu_clear(cpu_id, cpu_mask); if (*mmc != NO_CONTEXT) { local_irq_save(flags); *mmc = NO_CONTEXT; if (mm == current->mm) activate_context(mm); else cpu_clear(cpu_id, mm->cpu_vm_mask); local_irq_restore(flags); } if (!cpus_empty(cpu_mask)) flush_tlb_others(cpu_mask, mm, NULL, FLUSH_ALL); preempt_enable();}/*==========================================================================* * Name: smp_flush_tlb_range * * Description: This routine flushes a range of pages. * * Born on Date: 2002.02.05 * * Arguments: *mm - a pointer to the mm struct for flush TLB * start - not used * end - not used * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end){ smp_flush_tlb_mm(vma->vm_mm);}/*==========================================================================* * Name: smp_flush_tlb_page * * Description: This routine flushes one page. * * Born on Date: 2002.02.05 * * Arguments: *vma - a pointer to the vma struct include va * va - virtual address for flush TLB * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long va){ struct mm_struct *mm = vma->vm_mm; int cpu_id; cpumask_t cpu_mask; unsigned long *mmc; unsigned long flags; preempt_disable(); cpu_id = smp_processor_id(); mmc = &mm->context[cpu_id]; cpu_mask = mm->cpu_vm_mask; cpu_clear(cpu_id, cpu_mask);#ifdef DEBUG_SMP if (!mm) BUG();#endif if (*mmc != NO_CONTEXT) { local_irq_save(flags); va &= PAGE_MASK; va |= (*mmc & MMU_CONTEXT_ASID_MASK); __flush_tlb_page(va); local_irq_restore(flags); } if (!cpus_empty(cpu_mask)) flush_tlb_others(cpu_mask, mm, vma, va); preempt_enable();}/*==========================================================================* * Name: flush_tlb_others * * Description: This routine requests other CPU to execute flush TLB. * 1.Setup parmeters. * 2.Send 'INVALIDATE_TLB_IPI' to other CPU. * Request other CPU to execute 'smp_invalidate_interrupt()'. * 3.Wait for other CPUs operation finished. * * Born on Date: 2002.02.05 * * Arguments: cpumask - bitmap of target CPUs * *mm - a pointer to the mm struct for flush TLB * *vma - a pointer to the vma struct include va * va - virtual address for flush TLB * * Returns: void (cannot fail) * * Modification log: * Date Who Description * ---------- --- -------------------------------------------------------- * *==========================================================================*/static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm, struct vm_area_struct *vma, unsigned long va){ unsigned long *mask;#ifdef DEBUG_SMP unsigned long flags; __save_flags(flags); if (!(flags & 0x0040)) /* Interrupt Disable NONONO */ BUG();#endif /* DEBUG_SMP */ /* * A couple of (to be removed) sanity checks: * * - we do not send IPIs to not-yet booted CPUs. * - current CPU must not be in mask * - mask must exist :) */ BUG_ON(cpus_empty(cpumask)); BUG_ON(cpu_isset(smp_processor_id(), cpumask)); BUG_ON(!mm); /* If a CPU which we ran on has gone down, OK. */ cpus_and(cpumask, cpumask, cpu_online_map); if (cpus_empty(cpumask)) return; /* * i'm not happy about this global shared spinlock in the * MM hot path, but we'll see how contended it is. * Temporarily this turns IRQs off, so that lockups are * detected by the NMI watchdog. */ spin_lock(&tlbstate_lock); flush_mm = mm; flush_vma = vma; flush_va = va; mask=cpus_addr(cpumask); atomic_set_mask(*mask, (atomic_t *)&flush_cpumask); /* * We have to send the IPI only to * CPUs affected. */ send_IPI_mask(cpumask, INVALIDATE_TLB_IPI, 0); while (!cpus_empty(flush_cpumask)) { /* nothing. lockup detection does not belong here */ mb(); } flush_mm = NULL; flush_vma = NULL; flush_va = 0; spin_unlock(&tlbstate_lock);}/*==========================================================================* * Name: smp_invalidate_interrupt * * Description: This routine executes on CPU which received * 'INVALIDATE_TLB_IPI'. * 1.Flush local TLB. * 2.Report flush TLB process was finished. * * Born on Date: 2002.02.05 * * Arguments: NONE * * Returns: void (cannot fail) * * Modification log:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -