From owner-svn-src-head@FreeBSD.ORG Sat Jun 30 20:25:13 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66C6F1065670; Sat, 30 Jun 2012 20:25:13 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 526938FC26; Sat, 30 Jun 2012 20:25:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5UKPDwN039910; Sat, 30 Jun 2012 20:25:13 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5UKPDav039907; Sat, 30 Jun 2012 20:25:13 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <201206302025.q5UKPDav039907@svn.freebsd.org> From: Alan Cox Date: Sat, 30 Jun 2012 20:25:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237855 - in head/sys/amd64: amd64 include X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Sat, 30 Jun 2012 20:25:13 -0000 Author: alc Date: Sat Jun 30 20:25:12 2012 New Revision: 237855 URL: http://svn.freebsd.org/changeset/base/237855 Log: Optimize reserve_pv_entries() using the popcnt instruction. Modified: head/sys/amd64/amd64/pmap.c head/sys/amd64/include/cpufunc.h Modified: head/sys/amd64/amd64/pmap.c ============================================================================== --- head/sys/amd64/amd64/pmap.c Sat Jun 30 20:23:59 2012 (r237854) +++ head/sys/amd64/amd64/pmap.c Sat Jun 30 20:25:12 2012 (r237855) @@ -2408,9 +2408,15 @@ reserve_pv_entries(pmap_t pmap, int need retry: avail = 0; TAILQ_FOREACH(pc, &pmap->pm_pvchunk, pc_list) { - free = popcnt_pc_map_elem(pc->pc_map[0]); - free += popcnt_pc_map_elem(pc->pc_map[1]); - free += popcnt_pc_map_elem(pc->pc_map[2]); + if ((cpu_feature2 & CPUID2_POPCNT) == 0) { + free = popcnt_pc_map_elem(pc->pc_map[0]); + free += popcnt_pc_map_elem(pc->pc_map[1]); + free += popcnt_pc_map_elem(pc->pc_map[2]); + } else { + free = popcntq(pc->pc_map[0]); + free += popcntq(pc->pc_map[1]); + free += popcntq(pc->pc_map[2]); + } if (free == 0) break; avail += free; Modified: head/sys/amd64/include/cpufunc.h ============================================================================== --- head/sys/amd64/include/cpufunc.h Sat Jun 30 20:23:59 2012 (r237854) +++ head/sys/amd64/include/cpufunc.h Sat Jun 30 20:25:12 2012 (r237855) @@ -273,6 +273,15 @@ outw(u_int port, u_short data) __asm __volatile("outw %0, %w1" : : "a" (data), "Nd" (port)); } +static __inline u_long +popcntq(u_long mask) +{ + u_long result; + + __asm __volatile("popcntq %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + static __inline void mfence(void) {