Date: Wed, 21 Aug 2013 22:40:29 +0000 (UTC) From: Jung-uk Kim <jkim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254623 - in head/sys: amd64/include i386/include Message-ID: <201308212240.r7LMeT19044122@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jkim Date: Wed Aug 21 22:40:29 2013 New Revision: 254623 URL: http://svnweb.freebsd.org/changeset/base/254623 Log: Reimplement atomic operations on PDEs and PTEs in pmap.h. This change significantly reduces duplicate code and make it easier to read. Reviewed by: alc, bde Modified: head/sys/amd64/include/pmap.h head/sys/i386/include/pmap.h Modified: head/sys/amd64/include/pmap.h ============================================================================== --- head/sys/amd64/include/pmap.h Wed Aug 21 22:39:19 2013 (r254622) +++ head/sys/amd64/include/pmap.h Wed Aug 21 22:40:29 2013 (r254623) @@ -206,41 +206,14 @@ extern u_int64_t KPML4phys; /* physical pt_entry_t *vtopte(vm_offset_t); #define vtophys(va) pmap_kextract(((vm_offset_t) (va))) -static __inline pt_entry_t -pte_load(pt_entry_t *ptep) -{ - pt_entry_t r; - - r = *ptep; - return (r); -} - -static __inline pt_entry_t -pte_load_store(pt_entry_t *ptep, pt_entry_t pte) -{ - pt_entry_t r; - - __asm __volatile( - "xchgq %0,%1" - : "=m" (*ptep), - "=r" (r) - : "1" (pte), - "m" (*ptep)); - return (r); -} - -#define pte_load_clear(pte) atomic_readandclear_long(pte) - -static __inline void -pte_store(pt_entry_t *ptep, pt_entry_t pte) -{ +#define pte_load_store(ptep, pte) atomic_swap_long(ptep, pte) +#define pte_load_clear(ptep) atomic_swap_long(ptep, 0) +#define pte_store(ptep, pte) do { \ + *(u_long *)(ptep) = (u_long)(pte); \ +} while (0) +#define pte_clear(ptep) pte_store(ptep, 0) - *ptep = pte; -} - -#define pte_clear(ptep) pte_store((ptep), (pt_entry_t)0ULL) - -#define pde_store(pdep, pde) pte_store((pdep), (pde)) +#define pde_store(pdep, pde) pte_store(pdep, pde) extern pt_entry_t pg_nx; Modified: head/sys/i386/include/pmap.h ============================================================================== --- head/sys/i386/include/pmap.h Wed Aug 21 22:39:19 2013 (r254622) +++ head/sys/i386/include/pmap.h Wed Aug 21 22:40:29 2013 (r254623) @@ -326,98 +326,27 @@ pmap_kextract(vm_offset_t va) #if defined(PAE) && !defined(XEN) -#define pde_cmpset(pdep, old, new) \ - atomic_cmpset_64((pdep), (old), (new)) - -static __inline pt_entry_t -pte_load(pt_entry_t *ptep) -{ - pt_entry_t r; - - __asm __volatile( - "lock; cmpxchg8b %1" - : "=A" (r) - : "m" (*ptep), "a" (0), "d" (0), "b" (0), "c" (0)); - return (r); -} - -static __inline pt_entry_t -pte_load_store(pt_entry_t *ptep, pt_entry_t v) -{ - pt_entry_t r; - - r = *ptep; - __asm __volatile( - "1:\n" - "\tlock; cmpxchg8b %1\n" - "\tjnz 1b" - : "+A" (r) - : "m" (*ptep), "b" ((uint32_t)v), "c" ((uint32_t)(v >> 32))); - return (r); -} - -/* XXXRU move to atomic.h? */ -static __inline int -atomic_cmpset_64(volatile uint64_t *dst, uint64_t exp, uint64_t src) -{ - int64_t res = exp; - - __asm __volatile ( - " lock ; " - " cmpxchg8b %2 ; " - " setz %%al ; " - " movzbl %%al,%0 ; " - "# atomic_cmpset_64" - : "+A" (res), /* 0 (result) */ - "=m" (*dst) /* 1 */ - : "m" (*dst), /* 2 */ - "b" ((uint32_t)src), - "c" ((uint32_t)(src >> 32))); - - return (res); -} - -#define pte_load_clear(ptep) pte_load_store((ptep), (pt_entry_t)0ULL) - -#define pte_store(ptep, pte) pte_load_store((ptep), (pt_entry_t)pte) +#define pde_cmpset(pdep, old, new) atomic_cmpset_64_i586(pdep, old, new) +#define pte_load_store(ptep, pte) atomic_swap_64_i586(ptep, pte) +#define pte_load_clear(ptep) atomic_swap_64_i586(ptep, 0) +#define pte_store(ptep, pte) atomic_store_rel_64_i586(ptep, pte) extern pt_entry_t pg_nx; -#elif !defined(PAE) && !defined (XEN) - -#define pde_cmpset(pdep, old, new) \ - atomic_cmpset_int((pdep), (old), (new)) - -static __inline pt_entry_t -pte_load(pt_entry_t *ptep) -{ - pt_entry_t r; - - r = *ptep; - return (r); -} - -static __inline pt_entry_t -pte_load_store(pt_entry_t *ptep, pt_entry_t pte) -{ - __asm volatile("xchgl %0, %1" : "+m" (*ptep), "+r" (pte)); - return (pte); -} - -#define pte_load_clear(pte) atomic_readandclear_int(pte) - -static __inline void -pte_store(pt_entry_t *ptep, pt_entry_t pte) -{ +#elif !defined(PAE) && !defined(XEN) - *ptep = pte; -} +#define pde_cmpset(pdep, old, new) atomic_cmpset_int(pdep, old, new) +#define pte_load_store(ptep, pte) atomic_swap_int(ptep, pte) +#define pte_load_clear(ptep) atomic_swap_int(ptep, 0) +#define pte_store(ptep, pte) do { \ + *(u_int *)(ptep) = (u_int)(pte); \ +} while (0) #endif /* PAE */ -#define pte_clear(ptep) pte_store((ptep), (pt_entry_t)0ULL) +#define pte_clear(ptep) pte_store(ptep, 0) -#define pde_store(pdep, pde) pte_store((pdep), (pde)) +#define pde_store(pdep, pde) pte_store(pdep, pde) #endif /* _KERNEL */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308212240.r7LMeT19044122>