Support 64K pages mapping of SPE local stores on 4K kernel
Subsystems (5)
cover Support 64K pages mapping of SPE local stores on 4K kernel
This serie of patches supports userland mappings of SPE local stores using 64K hardware pages rather than 4K on a kernel using 4K pages to improve performances.
The current version of this serie relies on a hack to the generic code which is probably not acceptable upsteam. I have plans to do a proper fix but haven't had time to do it yet.
The first patch of the serie is fairly independant of the rest and should be applied to 2.6.21 as I beleive it fixes a bug with handling of huge pages from SPEs.
PATCH 1/5 powerpc: Fix spu SLB invalidations
The SPU code doesn't properly invalidate SPUs SLBs when necessary, for example when changing a segment size from the hugetlbfs code. In addition, it saves and restores the SLB content on context switches which makes it harder to properly handle those invalidations.
This patch removes the saving & restoring for now, something more efficient might be found later on. It also adds a spu_flush_all_slbs(mm) that can be used by the core mm code to flush the SLBs of all SPEs that are running a given mm at the time of the flush.
In order to do that, it adds a spinlock to the list of all SPEs and move some bits & pieces from spufs to spu_base.c
arch/powerpc/mm/hash_utils_64.c | 6 ++ arch/powerpc/mm/hugetlbpage.c | 4 + arch/powerpc/platforms/cell/spu_base.c | 81 ++++++++++++++++++++++++----- arch/powerpc/platforms/cell/spufs/sched.c | 13 ---- arch/powerpc/platforms/cell/spufs/switch.c | 62 +--------------------- include/asm-powerpc/spu.h | 7 ++ include/asm-powerpc/spu_csa.h | 4 - 7 files changed, 91 insertions(+), 86 deletions(-)
arch/powerpc/mm/hugetlbpage.c +4 -0
@@ -24,6 +24,7 @@#include <asm/machdep.h> #include <asm/cputable.h> #include <asm/tlb.h> +#include <asm/spu.h> #include <linux/sysctl.h>
@@ -513,6 +514,9 @@ int prepare_hugepage_range(unsigned longif ((addr + len) >0x100000000UL ) err =open_high_hpage_areas (current->mm,HTLB_AREA_MASK (addr, len)); +#ifdef CONFIG_SPE_BASE +spu_flush_all_slbs (current->mm); +#endif if (err) { printk(KERN_DEBUG "prepare_hugepage_range(%lx, %lx)" " failed (lowmask: 0x%04hx, highmask: 0x%04hx)\n",
arch/powerpc/platforms/cell/spu_base.c +69 -12
138 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/switch.c +3 -59
104 lines not on this page · raw message
include/asm-powerpc/spu.h +7 -0
@@ -165,6 +165,13 @@ int spu_irq_class_0_bottom(struct spu *sint spu_irq_class_1_bottom (struct spu *spu);void spu_irq_setaffinity (struct spu *spu,int cpu); +extern void spu_invalidate_slbs (struct spu *spu); +extern void spu_associate_mm (struct spu *spu,struct mm_struct *mm); + +/* Calls from the memory management to the SPU */ +struct mm_struct ; +extern void spu_flush_all_slbs (struct mm_struct *mm); +/* system callbacks from the SPU */ struct spu_syscall_block {u64 nr_ret;
include/asm-powerpc/spu_csa.h +0 -4
@@ -221,8 +221,6 @@ struct spu_priv2_collapsed {* @spu_chnlcnt_RW: Array of saved channel counts. * @spu_chnldata_RW: Array of saved channel data. * @suspend_time: Time stamp when decrementer disabled. -* @slb_esid_RW: Array of saved SLB esid entries. -* @slb_vsid_RW: Array of saved SLB vsid entries. * * Structure representing the whole of the SPU * context save area (CSA). This struct contains
@@ -245,8 +243,6 @@ struct spu_state {u32 spu_mailbox_data[4 ];u32 pu_mailbox_data[1 ];unsigned long suspend_time; -u64 slb_esid_RW[8 ]; -u64 slb_vsid_RW[8 ];spinlock_t register_lock; };
arch/powerpc/mm/hash_utils_64.c +6 -0
@@ -685,6 +685,9 @@ int hash_page(unsigned long ea, unsigned "non-cacheable mapping\n"); psize = mmu_vmalloc_psize =MMU_PAGE_4K ; } +#ifdef CONFIG_SPE_BASE +spu_flush_all_slbs (mm); +#endif }if (user_region) {if (psize !=get_paca ()->context.user_psize) {
@@ -759,6 +762,9 @@ void hash_preload(struct mm_struct *mm, mmu_psize_defs[MMU_PAGE_4K ].sllp;get_paca ()->context = mm->context;slb_flush_and_rebolt (); +#ifdef CONFIG_SPE_BASE +spu_flush_all_slbs (mm); +#endif } }if (mm->context.user_psize ==MMU_PAGE_64K )
arch/powerpc/platforms/cell/spufs/sched.c +2 -11
@@ -127,14 +127,6 @@ static void spu_remove_from_active_list(mutex_unlock (&spu_prio->active_mutex[node]); } -static inline void mm_needs_global_tlbie (struct mm_struct *mm) -{ -int nr = (NR_CPUS >1 ) ?NR_CPUS :NR_CPUS +1 ; - -/* Global TLBIE broadcast required with SPEs. */ -__cpus_setall (&mm->cpu_vm_mask, nr); -} -static BLOCKING_NOTIFIER_HEAD (spu_switch_notifier);static void spu_switch_notify (struct spu *spu,struct spu_context *ctx)
@@ -167,8 +159,7 @@ static void spu_bind_context(struct spu ctx->spu = spu; ctx->ops = &spu_hw_ops; spu->pid = current->pid; - spu->mm = ctx->owner; -mm_needs_global_tlbie (spu->mm); +spu_associate_mm (spu, ctx->owner); spu->ibox_callback = spufs_ibox_callback; spu->wbox_callback = spufs_wbox_callback; spu->stop_callback = spufs_stop_callback;
@@ -205,7 +196,7 @@ static void spu_unbind_context(struct sp spu->stop_callback =NULL ; spu->mfc_callback =NULL ; spu->dma_callback =NULL ; - spu->mm =NULL ; +spu_associate_mm (spu,NULL ); spu->pid =0 ; ctx->ops = &spu_backing_ops; ctx->spu =NULL ;
PATCH 2/5 This is a hack to get_unmapped_area to make the SPE 64K code work.
In reply to Benjamin Herrenschmidt(Though it might prove to not have nasty side effects ...)
The basic idea is that if the filesystem's get_unmapped_area was used, we skip the hugepage check. That assumes that the only filesytems that provide a g_u_a callback are either hugetlbfs itself, or filesystems that have arch specific code that "knows" already not to collide with hugetlbfs.
A proper fix will be done later, basically by removing the hugetlbfs hacks completely from get_unmapped_area and calling down to the mm and/or the filesytem g_u_a implementations for MAX_FIXED as well.
(Note that this will still rely on the fact that filesytems that provide a g_u_a "know" how to return areas that don't collide with hugetlbfs, thus the base assumption is the same as this hack)
mm/mmap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
mm/mmap.c +6 -3
@@ -1357,14 +1357,17 @@ unsigned long get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { - unsigned long ret; + unsigned long ret = 0; +int fs_area =0 ;if (!(flags &MAP_FIXED )) {unsigned long (*get_area)(struct file *,unsigned long ,unsigned long ,unsigned long ,unsigned long ); get_area = current->mm->get_unmapped_area; -if (file && file->f_op && file->f_op->get_unmapped_area) +if (file && file->f_op && file->f_op->get_unmapped_area) { get_area = file->f_op->get_unmapped_area; + fs_area =1 ; + } addr =get_area (file, addr, len, pgoff, flags);if (IS_ERR_VALUE (addr))return addr;
@@ -1380,7 +1383,7 @@ get_unmapped_area(struct file *file, uns* can be made suitable for hugepages. */ ret =prepare_hugepage_range (addr, len, pgoff); - }else { + }else if (!fs_area) {/* * Ensure that a normal request is not falling in a * reserved hugepage range. For some archs like IA-64,
PATCH 3/5 powerpc: Introduce address space "slices"
In reply to Benjamin HerrenschmidtThe basic issue is to be able to do what hugetlbfs does but with different page sizes for some other special filesystems, more specifically, my need is:
- Huge pages
- SPE local store mappings using 64K pages on a 4K base page size
kernel on Cell
- Some special 4K segments in 64K pages kernels for mapping a dodgy
specie of powerpc specific infiniband hardware that requires 4K MMU mappings for various reasons I won't explain here.
The main issues are:
- To maintain/keep track of the page size per "segments" (as we can
only have one page size per segment on powerpc, which are 256MB divisions of the address space).
- To make sure special mappings stay within their alloted
"segments" (including MAP_FIXED crap)
- To make sure everybody else doesn't mmap/brk/grow_stack into a
"segment" that is used for a special mapping
Some of the necessary mecanisms to handle that were present in the hugetlbfs code, but mostly in ways not suitable for anything else.
The patch address these in various ways described quickly below that hijack some of the existing hugetlbfs callbacks.
The ideal solution requires some changes to the generic get_unmapped_area(), among others, to get rid of the hugetlbfs hacks in there, and instead, make sure that the fs and mm get_unmapped_area are also called for MAP_FIXED. We might also need to add an mm callback to validate a mapping.
I intend to do those changes separately and then adapt this work to use them.
So what is a slice ? Well, I re-used the mecanism used formerly by our hugetlbfs implementation which divides the address space in "meta-segments" which I called "slices". The division is done using 256MB slices below 4G, and 1T slices above. Thus the address space is divided currently into 16 "low" slices and 16 "high" slices. (Special
case: high slice 0 is the area between 4G and 1T).
Doing so simplifies significantly the tracking of segments and avoid having to keep track of all the 256MB segments in the address space.
While I used the "concepts" of hugetlbfs, I mostly re-implemented everything in a more generic way and "ported" hugetlbfs to it.
slices can have an associated page size, which is encoded in the mmu context and used by the SLB miss handler to set the segment sizes. The hash code currently doesn't care, it has a specific check for hugepages, though I might add a mecanism to provide per-slice hash mapping functions in the future.
The slice code provide a pair of "generic" get_unmapped_area() (bottomup and topdown) functions that should work with any slice size. There is some trickyness here so I would appreciate people to have a look at the implementation of these and let me know if I got something wrong.
arch/powerpc/Kconfig | 5 arch/powerpc/kernel/asm-offsets.c | 16 arch/powerpc/mm/Makefile | 1 arch/powerpc/mm/hash_utils_64.c | 124 +++--- arch/powerpc/mm/hugetlbpage.c | 528 --------------------------- arch/powerpc/mm/mmu_context_64.c | 10 arch/powerpc/mm/slb.c | 11 arch/powerpc/mm/slb_low.S | 54 +- arch/powerpc/mm/slice.c | 630 +++++++++++++++++++++++++++++++++ arch/powerpc/platforms/cell/spu_base.c | 9 include/asm-powerpc/mmu.h | 12 include/asm-powerpc/paca.h | 2 include/asm-powerpc/page_64.h | 87 ++-- 13 files changed, 827 insertions(+), 662 deletions(-)
arch/powerpc/Kconfig +5 -0
@@ -318,6 +318,11 @@ config PPC_STD_MMU_32 def_bool y depends on PPC_STD_MMU && PPC32 +config PPC_MM_SLICES + bool + default y if HUGETLB_PAGE + default n + config VIRT_CPU_ACCOUNTING bool "Deterministic task and CPU time accounting" depends on PPC64
include/asm-powerpc/mmu.h +7 -5
@@ -355,15 +355,17 @@ typedef unsigned long mm_context_id_t;typedef struct {mm_context_id_t id; -u16 user_psize;/* page size index */ -u16 sllp;/* SLB entry page size encoding */ -#ifdef CONFIG_HUGETLB_PAGE -u16 low_htlb_areas, high_htlb_areas; +u16 user_psize;/* base page size index */ + +#ifdef CONFIG_PPC_MM_SLICES +u64 low_slices_psize;/* SLB page size encodings */ +u64 high_slices_psize;/* 4 bits per slice for now */ +#else +u16 sllp;/* SLB page size encoding */ #endif unsigned long vdso_base; }mm_context_t ; -static inline unsigned long vsid_scramble (unsigned long protovsid) {#if 0
include/asm-powerpc/paca.h +1 -1
@@ -82,8 +82,8 @@ struct paca_struct {mm_context_t context;u16 vmalloc_sllp; -u16 slb_cache[SLB_CACHE_ENTRIES ];u16 slb_cache_ptr; +u16 slb_cache[SLB_CACHE_ENTRIES ];/* * then miscellaneous read-write fields
include/asm-powerpc/page_64.h +43 -44
101 lines not on this page · raw message
arch/powerpc/mm/Makefile +1 -0
@@ -18,4 +18,5 @@ obj-$(CONFIG_40x) += 4xx_mmu.o obj-$(CONFIG_44x) += 44x_mmu.o obj-$(CONFIG_FSL_BOOKE) += fsl_booke_mmu.o obj-$(CONFIG_NEED_MULTIPLE_NODES) += numa.o +obj-$(CONFIG_PPC_MM_SLICES) += slice.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
arch/powerpc/mm/slice.c new file +630 -0
630 lines not on this page · raw message
arch/powerpc/kernel/asm-offsets.c +11 -5
@@ -123,12 +123,18 @@ int main(void)DEFINE (PACASLBCACHE , offsetof(struct paca_struct , slb_cache));DEFINE (PACASLBCACHEPTR , offsetof(struct paca_struct , slb_cache_ptr)); DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id)); - DEFINE(PACACONTEXTSLLP, offsetof(struct paca_struct, context.sllp));DEFINE (PACAVMALLOCSLLP , offsetof(struct paca_struct , vmalloc_sllp)); -#ifdef CONFIG_HUGETLB_PAGE - DEFINE(PACALOWHTLBAREAS, offsetof(struct paca_struct, context.low_htlb_areas)); - DEFINE(PACAHIGHHTLBAREAS, offsetof(struct paca_struct, context.high_htlb_areas)); -#endif /* CONFIG_HUGETLB_PAGE */ +#ifdef CONFIG_PPC_MM_SLICES +DEFINE (PACALOWSLICESPSIZE , offsetof(struct paca_struct , + context.low_slices_psize)); +DEFINE (PACAHIGHSLICEPSIZE , offsetof(struct paca_struct , + context.high_slices_psize)); +DEFINE (MMUPSIZEDEFSIZE ,sizeof (struct mmu_psize_def )); +DEFINE (MMUPSIZESLLP , offsetof(struct mmu_psize_def , sllp)); +#else + DEFINE(PACACONTEXTSLLP, offsetof(struct paca_struct, context.sllp)); + +#endif /* CONFIG_PPC_MM_SLICES */ DEFINE (PACA_EXGEN , offsetof(struct paca_struct , exgen));DEFINE (PACA_EXMC , offsetof(struct paca_struct , exmc));DEFINE (PACA_EXSLB , offsetof(struct paca_struct , exslb));
arch/powerpc/mm/hugetlbpage.c +12 -516
572 lines not on this page · raw message
arch/powerpc/mm/mmu_context_64.c +10 -0
@@ -28,6 +28,7 @@ int init_new_context(struct task_struct {int index;int err; +int new_context = (mm->context.id ==0 ); again:if (!idr_pre_get (&mmu_context_idr,GFP_KERNEL ))
@@ -50,9 +51,18 @@ again: } mm->context.id = index; +#ifdef CONFIG_PPC_MM_SLICES +/* The old code would re-promote on fork, we don't do that +* when using slices as it could cause problem promoting slices +* that have been forced down to 4K +*/ +if (new_context) +slice_set_user_psize (mm, mmu_virtual_psize); +#else mm->context.user_psize = mmu_virtual_psize; mm->context.sllp =SLB_VSID_USER | mmu_psize_defs[mmu_virtual_psize].sllp; +#endif return 0 ; }
arch/powerpc/mm/slb_low.S +34 -20
65 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +69 -55
170 lines not on this page · raw message
arch/powerpc/mm/slb.c +0 -11
@@ -198,12 +198,6 @@ void slb_initialize(void)static int slb_encoding_inited;extern unsigned int *slb_miss_kernel_load_linear;extern unsigned int *slb_miss_kernel_load_io; -#ifdef CONFIG_HUGETLB_PAGE -extern unsigned int *slb_miss_user_load_huge; -unsigned long huge_llp; - - huge_llp = mmu_psize_defs[mmu_huge_psize].sllp; -#endif /* Prepare our SLB miss handler based on our page size */ linear_llp = mmu_psize_defs[mmu_linear_psize].sllp;
@@ -220,11 +214,6 @@ void slb_initialize(void)DBG ("SLB: linear LLP = %04x\n" , linear_llp);DBG ("SLB: io LLP = %04x\n" , io_llp); -#ifdef CONFIG_HUGETLB_PAGE -patch_slb_encoding (slb_miss_user_load_huge, -SLB_VSID_USER | huge_llp); -DBG ("SLB: huge LLP = %04x\n" , huge_llp); -#endif }get_paca ()->stab_rr =SLB_NUM_BOLTED ;
arch/powerpc/platforms/cell/spu_base.c +4 -5
@@ -142,12 +142,11 @@ static int __spu_trap_data_seg(struct spswitch (REGION_ID (ea)) {case USER_REGION_ID : -#ifdef CONFIG_HUGETLB_PAGE -if (in_hugepage_area (mm->context, ea)) - psize = mmu_huge_psize; - else +#ifdef CONFIG_PPC_MM_SLICES + psize =get_slice_psize (mm, ea); +#else + psize = mm->context.user_psize;#endif - psize = mm->context.user_psize; vsid = (get_vsid (mm->context.id, ea) <<SLB_VSID_SHIFT ) |SLB_VSID_USER ;break ;
PATCH 1/1 Allow spufs to build as a module with slices enabled
The slice code is missing some exports to allow spufs to build as a module. Add them.
---
MODPOST 209 modules
WARNING: ".get_slice_psize" [arch/powerpc/platforms/cell/spufs/spufs.ko] undefined!
WARNING: ".slice_get_unmapped_area" [arch/powerpc/platforms/cell/spufs/spufs.ko] undefined!
--- arch/powerpc/mm/slice.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/mm/slice.c +3 -0
@@ -29,6 +29,7 @@#include <linux/pagemap.h> #include <linux/err.h> #include <linux/spinlock.h> +#include <linux/module.h> #include <asm/mman.h> #include <asm/mmu.h> #include <asm/spu.h>
@@ -499,6 +500,7 @@ unsigned long slice_get_unmapped_area(unreturn addr; } +EXPORT_SYMBOL (slice_get_unmapped_area); unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
@@ -537,6 +539,7 @@ unsigned int get_slice_psize(struct mm_sreturn (psizes >> (index *4 )) &0xf ; } +EXPORT_SYMBOL (get_slice_psize);/* * This is called by hash_page when it needs to do a lazy conversion of
Re: [Cbe-oss-dev] [PATCH] Allow spufs to build as a module with slices enabled
Quoted 2 lines · Michael Ellerman
The slice code is missing some exports to allow spufs to build as a module. Add them.
should be _GPL exports I think.
Re: [Cbe-oss-dev] [PATCH] Allow spufs to build as a module with slices enabled
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Michael Ellerman
The slice code is missing some exports to allow spufs to build as a module. Add them.
should be
_GPLexports I think.
Yeah of course, I just hacked it up to get it building and didn't think about it much. Benh said he'd add _GPL and respin the patch.
cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person
PATCH 4/5 powerpc: Add ability to 4K kernel to hash in 64K pages
In reply to Benjamin HerrenschmidtThis patch adds the ability for a kernel compiled with 4K page size to have special slices containing 64K pages and hash the right type of hash PTEs.
arch/powerpc/Kconfig | 6 ++++++ arch/powerpc/mm/hash_low_64.S | 5 ++++- arch/powerpc/mm/hash_utils_64.c | 36 +++++++++++++++++++++++------------- arch/powerpc/mm/tlb_64.c | 12 +++++++++--- include/asm-powerpc/pgtable-4k.h | 6 +++++- include/asm-powerpc/pgtable-64k.h | 7 ++++++- 6 files changed, 53 insertions(+), 19 deletions(-)
arch/powerpc/mm/hash_low_64.S +4 -1
@@ -612,6 +612,9 @@ htab_pte_insert_failure: li r3,-1 b htab_bail +#endif /* CONFIG_PPC_64K_PAGES */ + +#ifdef CONFIG_PPC_HAS_HASH_64K /***************************************************************************** * *
@@ -867,7 +870,7 @@ ht64_pte_insert_failure: b ht64_bail -#endif /* CONFIG_PPC_64K_PAGES */ +#endif /* CONFIG_PPC_HAS_HASH_64K */ /*****************************************************************************
include/asm-powerpc/pgtable-64k.h +6 -1
@@ -35,6 +35,11 @@#define _PAGE_HPTE_SUB 0x0ffff000/* combo only: sub pages HPTE bits */ #define _PAGE_HPTE_SUB0 0x08000000/* combo only: first sub page */ #define _PAGE_COMBO 0x10000000/* this is a combo 4k page */ + +/* Note the full page bits must be in the same location as for normal +* 4k pages as the same asssembly will be used to insert 64K pages +* wether the kernel has CONFIG_PPC_64K_PAGES or not +*/ #define _PAGE_F_SECOND 0x00008000/* full page: hidx bits */ #define _PAGE_F_GIX 0x00007000/* full page: hidx bits */
@@ -90,7 +95,7 @@#define pte_iterate_hashed_end () } while(0); } } while(0) -#define pte_pagesize_index (pte) \ +#define pte_pagesize_index (mm, addr, pte) \ (((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)#endif /* __ASSEMBLY__ */
arch/powerpc/Kconfig +6 -0
@@ -905,9 +905,15 @@ config NODES_SPAN_OTHER_NODES def_bool y depends on NEED_MULTIPLE_NODES +config PPC_HAS_HASH_64K + bool + depends on PPC64 + default n + config PPC_64K_PAGES bool "64k page size" depends on PPC64 + select PPC_HAS_HASH_64K help This option changes the kernel logical page size to 64k. On machines without processor support for 64k pages, the kernel will simulate
arch/powerpc/mm/hash_utils_64.c +23 -13
@@ -408,7 +408,7 @@ static void __init htab_finish_init(voidextern unsigned int *htab_call_hpte_remove;extern unsigned int *htab_call_hpte_updatepp; -#ifdef CONFIG_PPC_64K_PAGES +#ifdef CONFIG_PPC_HAS_HASH_64K extern unsigned int *ht64_call_hpte_insert1;extern unsigned int *ht64_call_hpte_insert2;extern unsigned int *ht64_call_hpte_remove;
@@ -658,7 +658,11 @@ int hash_page(unsigned long ea, unsignedreturn 1 ; } vsid =get_vsid (mm->context.id, ea); +#ifdef CONFIG_PPC_MM_SLICES + psize =get_slice_psize (mm, ea); +#else psize = mm->context.user_psize; +#endif break ;case VMALLOC_REGION_ID : mm = &init_mm;
@@ -688,8 +692,7 @@ int hash_page(unsigned long ea, unsigned#ifdef CONFIG_HUGETLB_PAGE /* Handle hugepage regions */ -if (HPAGE_SHIFT && -unlikely (get_slice_psize (mm, ea) == mmu_huge_psize)) { +if (HPAGE_SHIFT && psize == mmu_huge_psize) {DBG_LOW (" -> huge page !\n" );return hash_huge_page (mm, access, ea, vsid, local, trap); }
@@ -716,17 +719,22 @@ int hash_page(unsigned long ea, unsignedreturn 1 ; } -/* Do actual hashing */ -#ifndef CONFIG_PPC_64K_PAGES - rc =__hash_page_4K (ea, access, vsid, ptep, trap, local); -#else +/* Handle demotion to 4K pages in situations where 64K pages are +* not supported for cache inhibited mappings +*/ +#ifdef CONFIG_PPC_64K_PAGES if (mmu_ci_restrictions) - psize =hash_handle_ci_restrictions (mm, ea, ptep, psize, user_region); + psize =hash_handle_ci_restrictions (mm, ea, ptep, psize, + user_region); +#endif /* CONFIG_PPC_64K_PAGES */ + +/* Do actual hashing */ +#ifdef CONFIG_PPC_HAS_HASH_64K if (psize ==MMU_PAGE_64K ) rc =__hash_page_64K (ea, access, vsid, ptep, trap, local); else +#endif /* CONFIG_PPC_HAS_HASH_64K */ rc =__hash_page_4K (ea, access, vsid, ptep, trap, local); -#endif /* CONFIG_PPC_64K_PAGES */ #ifndef CONFIG_PPC_64K_PAGES DBG_LOW (" o-pte: %016lx\n" ,pte_val (*ptep));
@@ -775,17 +783,19 @@ void hash_preload(struct mm_struct *mm, mask =cpumask_of_cpu (smp_processor_id ());if (cpus_equal (mm->cpu_vm_mask, mask)) local =1 ; + psize = mm->context.user_psize; -#ifndef CONFIG_PPC_64K_PAGES -__hash_page_4K (ea, access, vsid, ptep, trap, local); -#else +#ifdef CONFIG_PPC_64K_PAGES if (mmu_ci_restrictions) psize =hash_handle_ci_restrictions (mm, ea, ptep, psize,1 ); +#endif /* CONFIG_PPC_64K_PAGES */ + +#ifdef CONFIG_PPC_HAS_HASH_64K if (psize ==MMU_PAGE_64K )__hash_page_64K (ea, access, vsid, ptep, trap, local); else -__hash_page_4K (ea, access, vsid, ptep, trap, local);#endif /* CONFIG_PPC_64K_PAGES */ +__hash_page_4K (ea, access, vsid, ptep, trap, local);local_irq_restore (flags); }
arch/powerpc/mm/tlb_64.c +9 -3
@@ -140,16 +140,22 @@ void hpte_update(struct mm_struct *mm, u*/ addr &=PAGE_MASK ; -/* Get page size (maybe move back to caller) */ +/* Get page size (maybe move back to caller). +* +* NOTE: when using special 64K mappings in 4K environment like +* for SPEs, we obtain the page size from the slice, which thus +* must still exist (and thus the VMA not reused) at the time +* of this call +*/ if (huge) {#ifdef CONFIG_HUGETLB_PAGE psize = mmu_huge_psize;#else BUG (); - psize =pte_pagesize_index (pte);/* shutup gcc */ + psize =pte_pagesize_index (mm, addr, pte);/* shutup gcc */ #endif }else - psize =pte_pagesize_index (pte); + psize =pte_pagesize_index (mm, addr, pte);/* * This can happen when we are in the middle of a TLB batch and
include/asm-powerpc/pgtable-4k.h +5 -1
@@ -78,7 +78,11 @@#define pte_iterate_hashed_end () } while(0) -#define pte_pagesize_index (pte) MMU_PAGE_4K +#ifdef CONFIG_PPC_HAS_HASH_64K +#define pte_pagesize_index (mm, addr, pte) get_slice_psize(mm, addr) +#else +#define pte_pagesize_index (mm, addr, pte) MMU_PAGE_4K +#endif /* * 4-level page tables related bits
PATCH 5/5 powerpc: spufs support for 64K LS mappings on 4K kernels
In reply to Benjamin HerrenschmidtThis patch adds an option to spufs when the kernel is configured for 4K page to give it the ability to use 64K pages for SPE local store mappings.
Currently, we are optimistic and try order 4 allocations when creting contexts. If that fails, the code will fallback to 4K automatically.
arch/powerpc/platforms/cell/Kconfig | 15 + arch/powerpc/platforms/cell/spufs/Makefile | 2 arch/powerpc/platforms/cell/spufs/context.c | 4 arch/powerpc/platforms/cell/spufs/file.c | 77 ++++++++-- arch/powerpc/platforms/cell/spufs/lscsa_alloc.c | 181 ++++++++++++++++++++++++ arch/powerpc/platforms/cell/spufs/switch.c | 28 +-- include/asm-powerpc/spu_csa.h | 10 + 7 files changed, 282 insertions(+), 35 deletions(-)
arch/powerpc/platforms/cell/Kconfig +15 -0
@@ -12,6 +12,21 @@ config SPU_FS Units on machines implementing the Broadband Processor Architecture. +config SPU_FS_64K_LS + bool "Use 64K pages to map SPE local store" + # we depend on PPC_MM_SLICES for now rather than selecting + # it because we depend on hugetlbfs hooks being present. We + # will fix that when the generic code has been improved to + # not require hijacking hugetlbfs hooks. + depends on SPU_FS && PPC_MM_SLICES && !PPC_64K_PAGES + default y + select PPC_HAS_HASH_64K + help + This option causes SPE local stores to be mapped in process + address spaces using 64K pages while the rest of the kernel + uses 4K pages. This can improve performances of applications + using multiple SPEs by lowering the TLB pressure on them. + config SPU_BASE bool default n
arch/powerpc/platforms/cell/spufs/context.c +1 -3
@@ -36,10 +36,8 @@ struct spu_context *alloc_spu_context(st/* Binding to physical processor deferred * until spu_activate(). */ -spu_init_csa (&ctx->csa); -if (!ctx->csa.lscsa) { +if (spu_init_csa (&ctx->csa)) goto out_free; - }spin_lock_init (&ctx->mmio_lock);kref_init (&ctx->kref);mutex_init (&ctx->state_mutex);
arch/powerpc/platforms/cell/spufs/switch.c +9 -19
@@ -2185,40 +2185,30 @@ static void init_priv2(struct spu_state* as it is by far the largest of the context save regions, * and may need to be pinned or otherwise specially aligned. */ -void spu_init_csa (struct spu_state *csa) +int spu_init_csa (struct spu_state *csa) { -struct spu_lscsa *lscsa; -unsigned char *p; +int rc;if (!csa) -return ; +return -EINVAL ;memset (csa,0 ,sizeof (struct spu_state )); - lscsa =vmalloc (sizeof (struct spu_lscsa )); -if (!lscsa) -return ; + rc =spu_alloc_lscsa (csa); +if (rc) +return rc; -memset (lscsa,0 ,sizeof (struct spu_lscsa )); - csa->lscsa = lscsa;spin_lock_init (&csa->register_lock); -/* Set LS pages reserved to allow for user-space mapping. */ -for (p = lscsa->ls; p < lscsa->ls +LS_SIZE ; p +=PAGE_SIZE ) -SetPageReserved (vmalloc_to_page (p)); -init_prob (csa);init_priv1 (csa);init_priv2 (csa); + +return 0 ; }EXPORT_SYMBOL_GPL (spu_init_csa);void spu_fini_csa (struct spu_state *csa) { -/* Clear reserved bit before vfree. */ -unsigned char *p; -for (p = csa->lscsa->ls; p < csa->lscsa->ls +LS_SIZE ; p +=PAGE_SIZE ) -ClearPageReserved (vmalloc_to_page (p)); - -vfree (csa->lscsa); +spu_free_lscsa (csa); }EXPORT_SYMBOL_GPL (spu_fini_csa);
include/asm-powerpc/spu_csa.h +9 -1
@@ -235,6 +235,12 @@ struct spu_priv2_collapsed {*/ struct spu_state {struct spu_lscsa *lscsa; +#ifdef CONFIG_SPU_FS_64K_LS +int use_big_pages; +/* One struct page per 64k page */ +#define SPU_LSCSA_NUM_BIG_PAGES (sizeof(struct spu_lscsa) / 0x10000) +struct page *lscsa_pages[SPU_LSCSA_NUM_BIG_PAGES ]; +#endif struct spu_problem_collapsed prob;struct spu_priv1_collapsed priv1;struct spu_priv2_collapsed priv2;
@@ -246,12 +252,14 @@ struct spu_state {spinlock_t register_lock; }; -extern void spu_init_csa (struct spu_state *csa); +extern int spu_init_csa (struct spu_state *csa);extern void spu_fini_csa (struct spu_state *csa);extern int spu_save (struct spu_state *prev,struct spu *spu);extern int spu_restore (struct spu_state *new,struct spu *spu);extern int spu_switch (struct spu_state *prev,struct spu_state *new,struct spu *spu); +extern int spu_alloc_lscsa (struct spu_state *csa); +extern void spu_free_lscsa (struct spu_state *csa);#endif /* !__SPU__ */ #endif /* __KERNEL__ */
arch/powerpc/platforms/cell/spufs/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-y += switch.o +obj-y += switch.o lscsa_alloc.o obj-$(CONFIG_SPU_FS) += spufs.o spufs-y += inode.o file.o context.o syscalls.o coredump.o
arch/powerpc/platforms/cell/spufs/lscsa_alloc.c new file +181 -0
181 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/file.c +66 -11
101 lines not on this page · raw message
Quoted 11 lines · Benjamin Herrenschmidt
This serie of patches supports userland mappings of SPE local stores using 64K hardware pages rather than 4K on a kernel using 4K pages to improve performances.
The current version of this serie relies on a hack to the generic code which is probably not acceptable upsteam. I have plans to do a proper fix but haven't had time to do it yet.
The first patch of the serie is fairly independant of the rest and should be applied to 2.6.21 as I beleive it fixes a bug with handling of huge pages from SPEs.
Unfortunately this seems to break a test case I have which dmas between two SPEs.
The process just seems to hang, the machine is still pingable. gdb hangs attaching to the spu process, but killing the spu process from another console seems to return the system to normal.
cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person