From owner-svn-src-head@FreeBSD.ORG Wed Aug 21 22:40:30 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5800ADB2; Wed, 21 Aug 2013 22:40:30 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 44C1823E1; Wed, 21 Aug 2013 22:40:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7LMeUvh044125; Wed, 21 Aug 2013 22:40:30 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7LMeT19044122; Wed, 21 Aug 2013 22:40:29 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201308212240.r7LMeT19044122@svn.freebsd.org> From: Jung-uk Kim Date: Wed, 21 Aug 2013 22:40:29 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Aug 2013 22:40:30 -0000 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 */