powerpc/mm/hash: Simplify the region id calculation.
authorAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Wed, 17 Apr 2019 12:59:17 +0000 (18:29 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 21 Apr 2019 13:12:40 +0000 (23:12 +1000)
This reduces multiple comparisons in get_region_id to a bit shift operation.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/book3s/64/hash-4k.h
arch/powerpc/include/asm/book3s/64/hash-64k.h
arch/powerpc/include/asm/book3s/64/hash.h
arch/powerpc/include/asm/book3s/64/mmu-hash.h

index 4c9dfd6254616fc632d9e0bfefd67859fee082af..8fd8599c9395c77a5a3f2fef8ebb6884b8e4b738 100644 (file)
  */
 #define MAX_EA_BITS_PER_CONTEXT                46
 
+#define REGION_SHIFT           (MAX_EA_BITS_PER_CONTEXT - 2)
+
 /*
  * Our page table limit us to 64TB. Hence for the kernel mapping,
  * each MAP area is limited to 16 TB.
  * The four map areas are:  linear mapping, vmap, IO and vmemmap
  */
-#define H_KERN_MAP_SIZE                (ASM_CONST(1) << (MAX_EA_BITS_PER_CONTEXT - 2))
+#define H_KERN_MAP_SIZE                (ASM_CONST(1) << REGION_SHIFT)
 
 /*
  * Define the address range of the kernel non-linear virtual area
index 0d0191cda0507adc15bb2a937de1806c0421633b..d1d9177d9ebddaaa1fcf34588a68e05f3f4f3e4d 100644 (file)
@@ -13,6 +13,7 @@
  * is handled in the hotpath.
  */
 #define MAX_EA_BITS_PER_CONTEXT                49
+#define REGION_SHIFT           MAX_EA_BITS_PER_CONTEXT
 
 /*
  * We use one context for each MAP area.
index 76741a22191087d3afd7619ff3b26484a4ae46aa..7faa3d7214c04a74c3331273cd51ec27524cabf9 100644 (file)
 #define H_VMEMMAP_SIZE         H_KERN_MAP_SIZE
 #define H_VMEMMAP_END          (H_VMEMMAP_START + H_VMEMMAP_SIZE)
 
+#define NON_LINEAR_REGION_ID(ea)       ((((unsigned long)ea - H_KERN_VIRT_START) >> REGION_SHIFT) + 2)
+
 /*
  * Region IDs
  */
-#define USER_REGION_ID         1
-#define KERNEL_REGION_ID       2
-#define VMALLOC_REGION_ID      3
-#define IO_REGION_ID           4
-#define VMEMMAP_REGION_ID      5
+#define USER_REGION_ID         0
+#define KERNEL_REGION_ID       1
+#define VMALLOC_REGION_ID      NON_LINEAR_REGION_ID(H_VMALLOC_START)
+#define IO_REGION_ID           NON_LINEAR_REGION_ID(H_KERN_IO_START)
+#define VMEMMAP_REGION_ID      NON_LINEAR_REGION_ID(H_VMEMMAP_START)
 
 /*
  * Defines the address of the vmemap area, in its own region on
  * hash table CPUs.
  */
-
 #ifdef CONFIG_PPC_MM_SLICES
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
 #endif /* CONFIG_PPC_MM_SLICES */
 
-
 /* PTEIDX nibble */
 #define _PTEIDX_SECONDARY      0x8
 #define _PTEIDX_GROUP_IX       0x7
 #ifndef __ASSEMBLY__
 static inline int get_region_id(unsigned long ea)
 {
+       int region_id;
        int id = (ea >> 60UL);
 
        if (id == 0)
                return USER_REGION_ID;
 
-       VM_BUG_ON(id != 0xc);
-       VM_BUG_ON(ea >= H_VMEMMAP_END);
+       if (ea < H_KERN_VIRT_START)
+               return KERNEL_REGION_ID;
 
-       if (ea >= H_VMEMMAP_START)
-               return VMEMMAP_REGION_ID;
-       else if (ea >= H_KERN_IO_START)
-               return IO_REGION_ID;
-       else if (ea >= H_VMALLOC_START)
-               return VMALLOC_REGION_ID;
+       VM_BUG_ON(id != 0xc);
+       BUILD_BUG_ON(NON_LINEAR_REGION_ID(H_VMALLOC_START) != 2);
 
-       return KERNEL_REGION_ID;
+       region_id = NON_LINEAR_REGION_ID(ea);
+       VM_BUG_ON(region_id > VMEMMAP_REGION_ID);
+       return region_id;
 }
 
 #define        hash__pmd_bad(pmd)              (pmd_val(pmd) & H_PMD_BAD_BITS)
index 8a30bf189f1099c1afd80b13e7b666fe10e266d9..9a9adbeef0706165f8bf53e0cb95ff588e6f0c15 100644 (file)
@@ -823,7 +823,7 @@ static inline unsigned long get_kernel_context(unsigned long ea)
                 */
                ctx =  1 + ((ea & EA_MASK) >> MAX_EA_BITS_PER_CONTEXT);
        } else
-               ctx = region_id + MAX_KERNEL_CTX_CNT - 2;
+               ctx = region_id + MAX_KERNEL_CTX_CNT - 1;
        return ctx;
 }