Author: jah
Date: Sun Jan 29 16:54:55 2017
New Revision: 312952
URL: https://svnweb.freebsd.org/changeset/base/312952

Log:
  Implement get_pcpu() for i386 and use it to replace pcpu_find(curcpu)
  in the i386 pmap.
  
  The curcpu macro loads the per-cpu data pointer as its first step,
  so the remaining steps of pcpu_find(curcpu) are circular.
  
  get_pcpu() is already implemented for arm, arm64, and risc-v.
  My plan is to implement it for the remaining architectures and use
  it to replace several instances of pcpu_find(curcpu) in MI code.
  
  Reviewed by:  kib
  MFC after:    1 week
  Differential Revision:        https://reviews.freebsd.org/D9370

Modified:
  head/sys/i386/i386/pmap.c
  head/sys/i386/include/pcpu.h

Modified: head/sys/i386/i386/pmap.c
==============================================================================
--- head/sys/i386/i386/pmap.c   Sun Jan 29 14:29:02 2017        (r312951)
+++ head/sys/i386/i386/pmap.c   Sun Jan 29 16:54:55 2017        (r312952)
@@ -440,7 +440,7 @@ pmap_bootstrap(vm_paddr_t firstaddr)
         * CMAP1/CMAP2 are used for zeroing and copying pages.
         * CMAP3 is used for the boot-time memory test.
         */
-       pc = pcpu_find(curcpu);
+       pc = get_pcpu();
        mtx_init(&pc->pc_cmap_lock, "SYSMAPS", NULL, MTX_DEF);
        SYSMAP(caddr_t, pc->pc_cmap_pte1, pc->pc_cmap_addr1, 1)
        SYSMAP(caddr_t, pc->pc_cmap_pte2, pc->pc_cmap_addr2, 1)
@@ -4206,7 +4206,7 @@ pmap_zero_page(vm_page_t m)
        struct pcpu *pc;
 
        sched_pin();
-       pc = pcpu_find(curcpu);
+       pc = get_pcpu();
        cmap_pte2 = pc->pc_cmap_pte2;
        mtx_lock(&pc->pc_cmap_lock);
        if (*cmap_pte2)
@@ -4237,7 +4237,7 @@ pmap_zero_page_area(vm_page_t m, int off
        struct pcpu *pc;
 
        sched_pin();
-       pc = pcpu_find(curcpu);
+       pc = get_pcpu();
        cmap_pte2 = pc->pc_cmap_pte2;
        mtx_lock(&pc->pc_cmap_lock);
        if (*cmap_pte2)
@@ -4264,7 +4264,7 @@ pmap_copy_page(vm_page_t src, vm_page_t 
        struct pcpu *pc;
 
        sched_pin();
-       pc = pcpu_find(curcpu);
+       pc = get_pcpu();
        cmap_pte1 = pc->pc_cmap_pte1; 
        cmap_pte2 = pc->pc_cmap_pte2;
        mtx_lock(&pc->pc_cmap_lock);
@@ -4299,7 +4299,7 @@ pmap_copy_pages(vm_page_t ma[], vm_offse
        int cnt;
 
        sched_pin();
-       pc = pcpu_find(curcpu);
+       pc = get_pcpu();
        cmap_pte1 = pc->pc_cmap_pte1; 
        cmap_pte2 = pc->pc_cmap_pte2;
        mtx_lock(&pc->pc_cmap_lock);
@@ -5288,7 +5288,7 @@ pmap_flush_page(vm_page_t m)
        useclflushopt = (cpu_stdext_feature & CPUID_STDEXT_CLFLUSHOPT) != 0;
        if (useclflushopt || (cpu_feature & CPUID_CLFSH) != 0) {
                sched_pin();
-               pc = pcpu_find(curcpu);
+               pc = get_pcpu();
                cmap_pte2 = pc->pc_cmap_pte2; 
                mtx_lock(&pc->pc_cmap_lock);
                if (*cmap_pte2)

Modified: head/sys/i386/include/pcpu.h
==============================================================================
--- head/sys/i386/include/pcpu.h        Sun Jan 29 14:29:02 2017        
(r312951)
+++ head/sys/i386/include/pcpu.h        Sun Jan 29 16:54:55 2017        
(r312952)
@@ -76,6 +76,7 @@
 
 extern struct pcpu *pcpup;
 
+#define        get_pcpu()              (pcpup)
 #define        PCPU_GET(member)        (pcpup->pc_ ## member)
 #define        PCPU_ADD(member, val)   (pcpup->pc_ ## member += (val))
 #define        PCPU_INC(member)        PCPU_ADD(member, 1)
@@ -196,6 +197,15 @@ extern struct pcpu *pcpup;
        }                                                               \
 } while (0)
 
+#define        get_pcpu() __extension__ ({                                     
\
+       struct pcpu *__pc;                                              \
+                                                                       \
+       __asm __volatile("movl %%fs:%1,%0"                              \
+           : "=r" (__pc)                                               \
+           : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace))));      \
+       __pc;                                                           \
+})
+
 #define        PCPU_GET(member)        __PCPU_GET(pc_ ## member)
 #define        PCPU_ADD(member, val)   __PCPU_ADD(pc_ ## member, val)
 #define        PCPU_INC(member)        __PCPU_INC(pc_ ## member)
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to